diff options
author | Nicholas <nbnoll@eml.cc> | 2021-11-10 20:12:45 -0800 |
---|---|---|
committer | Nicholas <nbnoll@eml.cc> | 2021-11-11 08:16:47 -0800 |
commit | 7ea1cdb7d31f00024f5a1d124b42cd19a03b959a (patch) | |
tree | f65abf9fa32856287de586129d4ed7c1c473864a /sys/libutf/findlast.c | |
parent | 43688fe7190d0350349d47727c3663421d5618dc (diff) |
chore: libunicode -> libutf
Diffstat (limited to 'sys/libutf/findlast.c')
-rw-r--r-- | sys/libutf/findlast.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/sys/libutf/findlast.c b/sys/libutf/findlast.c new file mode 100644 index 0000000..ab25ab2 --- /dev/null +++ b/sys/libutf/findlast.c @@ -0,0 +1,32 @@ +#include "internal.h" + +byte* +utf8·findlast(byte* s, rune c) +{ + long c1; + rune r; + byte *l; + + if(c < Tx) + return strrchr(s, c); + + l = nil; + for(;;){ + c1 = *(ubyte*)s; + if(c1 < Tx){ + if(c1 == 0) return l; + if(c1 == c) l = s; + s++; + continue; + } + + c1 = utf8·decode(s, &r); + + if(r == c) + l = s; + + s += c1; + } + + return nil; +} |