From c0e510b356643089d132688b58a4e02f28f05677 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 31 May 2024 19:11:52 +0200 Subject: Add uprop_get_wdth() and ucswdth() --- lib/unicode/string/u8wdth.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 lib/unicode/string/u8wdth.c (limited to 'lib/unicode/string') 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; +} -- cgit v1.2.3