aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-05-04 02:21:49 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-05-04 02:21:49 +0200
commit8b923ba5e5bb37ea26350b4c1c688b8697706609 (patch)
treef0a128daf3b5a115d0b1ca9b5fccd9914386381e /lib
parente5a4bfe05bea551fc17048548695810a1ca48f5c (diff)
Add u8split()
Diffstat (limited to 'lib')
-rw-r--r--lib/mbstring/u8split.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/mbstring/u8split.c b/lib/mbstring/u8split.c
new file mode 100644
index 0000000..5ee3bc0
--- /dev/null
+++ b/lib/mbstring/u8split.c
@@ -0,0 +1,16 @@
+#include "mbstring.h"
+
+struct u8view
+u8split(const char8_t **p, size_t *n, rune ch)
+{
+ struct u8view lhs = {.p = *p};
+ if ((*p = u8chr(*p, *n, ch)) == nullptr) {
+ lhs.len = *n;
+ *n = 0;
+ } else {
+ lhs.len = *p - lhs.p;
+ *n -= lhs.len;
+ u8next(nullptr, p, n);
+ }
+ return lhs;
+}