aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-05-31 20:31:55 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-05-31 20:31:55 +0200
commit604b18befd9918a65a8f370a6051864fcda2f623 (patch)
tree1305a779a81ebbd0f856158cc78555728d6376af
parentc0e510b356643089d132688b58a4e02f28f05677 (diff)
Pass a tabsize to ucswdth()
-rw-r--r--include/unicode/string.h4
-rw-r--r--lib/unicode/string/u8wdth.c12
2 files changed, 10 insertions, 6 deletions
diff --git a/include/unicode/string.h b/include/unicode/string.h
index ed082a1..6908fe7 100644
--- a/include/unicode/string.h
+++ b/include/unicode/string.h
@@ -30,7 +30,7 @@ enum normform {
/* clang-format on */
-[[nodiscard]] size_t u8wdth(struct u8view);
+[[nodiscard]] size_t u8wdth(struct u8view, int);
[[nodiscard]] size_t u8gcnt(struct u8view);
[[nodiscard]] size_t u8wcnt(struct u8view);
[[nodiscard]] size_t u8wcnt_human(struct u8view);
@@ -49,7 +49,7 @@ size_t u8wnext_human(struct u8view *, struct u8view *);
enum normform);
/* Encoding-generic macros */
-#define ucswdth(sv) _Generic((sv), struct u8view: u8wdth)((sv))
+#define ucswdth(sv, ts) _Generic((sv), struct u8view: u8wdth)((sv), (ts))
#define ucsgcnt(sv) _Generic((sv), struct u8view: u8gcnt)((sv))
#define ucswcnt(sv) _Generic((sv), struct u8view: u8wcnt)((sv))
#define ucswcnt_human(sv) _Generic((sv), struct u8view: u8wcnt_human)((sv))
diff --git a/lib/unicode/string/u8wdth.c b/lib/unicode/string/u8wdth.c
index 503ff7c..7a58069 100644
--- a/lib/unicode/string/u8wdth.c
+++ b/lib/unicode/string/u8wdth.c
@@ -3,15 +3,19 @@
#include "unicode/string.h"
size_t
-u8wdth(struct u8view sv)
+u8wdth(struct u8view sv, int ts)
{
rune ch;
size_t n = 0;
while (ucsnext(&ch, &sv) != 0) {
- int w = uprop_get_wdth(ch);
- if (w > 0)
- n += w;
+ if (ch == '\t')
+ n += ts - n % ts;
+ else {
+ int w = uprop_get_wdth(ch);
+ if (w > 0)
+ n += w;
+ }
}
return n;