aboutsummaryrefslogtreecommitdiff
path: root/lib/unicode
diff options
context:
space:
mode:
Diffstat (limited to 'lib/unicode')
-rw-r--r--lib/unicode/string/u8wcnt_human.c10
-rw-r--r--lib/unicode/string/u8wnext_human.c27
2 files changed, 37 insertions, 0 deletions
diff --git a/lib/unicode/string/u8wcnt_human.c b/lib/unicode/string/u8wcnt_human.c
new file mode 100644
index 0000000..6e70398
--- /dev/null
+++ b/lib/unicode/string/u8wcnt_human.c
@@ -0,0 +1,10 @@
+#include "unicode/string.h"
+
+size_t
+u8wcnt_human(const char8_t *s, size_t n)
+{
+ size_t m = 0;
+ while (u8wnext_human(nullptr, &s, &n))
+ m++;
+ return m;
+}
diff --git a/lib/unicode/string/u8wnext_human.c b/lib/unicode/string/u8wnext_human.c
new file mode 100644
index 0000000..d85abf1
--- /dev/null
+++ b/lib/unicode/string/u8wnext_human.c
@@ -0,0 +1,27 @@
+#include "macros.h"
+#include "mbstring.h"
+#include "unicode/prop.h"
+#include "unicode/string.h"
+
+size_t
+u8wnext_human(struct u8view *dst, const char8_t **s, size_t *n)
+{
+ ASSUME(n != nullptr);
+ ASSUME(s != nullptr);
+ ASSUME(*s != nullptr);
+
+ struct u8view w;
+ while (u8wnext(&w, s, n)) {
+ rune ch;
+ struct u8view cpy = w;
+ while (u8next(&ch, U8_ARGSP(cpy))) {
+ if (uprop_get_gc(ch) & (GC_L | GC_N)) {
+ if (dst != nullptr)
+ *dst = w;
+ return w.len;
+ }
+ }
+ }
+
+ return 0;
+}