aboutsummaryrefslogtreecommitdiff
path: root/lib/unicode/string
diff options
context:
space:
mode:
Diffstat (limited to 'lib/unicode/string')
-rw-r--r--lib/unicode/string/u8wdth.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/unicode/string/u8wdth.c b/lib/unicode/string/u8wdth.c
new file mode 100644
index 0000000..503ff7c
--- /dev/null
+++ b/lib/unicode/string/u8wdth.c
@@ -0,0 +1,18 @@
+#include "mbstring.h"
+#include "unicode/prop.h"
+#include "unicode/string.h"
+
+size_t
+u8wdth(struct u8view sv)
+{
+ rune ch;
+ size_t n = 0;
+
+ while (ucsnext(&ch, &sv) != 0) {
+ int w = uprop_get_wdth(ch);
+ if (w > 0)
+ n += w;
+ }
+
+ return n;
+}