aboutsummaryrefslogtreecommitdiff
path: root/lib/unicode/string
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-05-31 19:11:52 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-05-31 19:16:00 +0200
commitc0e510b356643089d132688b58a4e02f28f05677 (patch)
treeed75a964a2ec9ad4a01ae03f16510eda00ecc2dc /lib/unicode/string
parent114b88f931c7d99d88ad976f6e7c5bb67f1a830d (diff)
Add uprop_get_wdth() and ucswdth()
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;
+}