aboutsummaryrefslogtreecommitdiff
path: root/sys/libutf/find.c
diff options
context:
space:
mode:
authorNicholas <nbnoll@eml.cc>2021-11-10 20:12:45 -0800
committerNicholas <nbnoll@eml.cc>2021-11-10 20:12:45 -0800
commitb5de2d7bd1e08d27f7780434e601d6d3a0750583 (patch)
tree1d12af8a2c5903f1eef3b967e52474a244e78257 /sys/libutf/find.c
parent0a1041044141ddbda0c67602e70fe8894e7430fd (diff)
chore: libunicode -> libutf
Diffstat (limited to 'sys/libutf/find.c')
-rw-r--r--sys/libutf/find.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/sys/libutf/find.c b/sys/libutf/find.c
new file mode 100644
index 0000000..d75feb8
--- /dev/null
+++ b/sys/libutf/find.c
@@ -0,0 +1,31 @@
+#include "internal.h"
+
+byte*
+utf8·find(byte* s, rune c)
+{
+ long c1;
+ rune r;
+ int n;
+
+ if(c < Tx)
+ return strchr(s, c);
+
+ for(;;){
+ c1 = *(ubyte*)s;
+ if(c1 < Tx){
+ if(c1 == 0) return nil;
+ if(c1 == c) return s;
+ s++;
+ continue;
+ }
+
+ n = utf8·decode(s, &r);
+
+ if(r == c)
+ return s;
+
+ s += n;
+ }
+
+ return nil;
+}