diff options
Diffstat (limited to 'lib9/utfrune.c')
| -rw-r--r-- | lib9/utfrune.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib9/utfrune.c b/lib9/utfrune.c new file mode 100644 index 00000000..a2737471 --- /dev/null +++ b/lib9/utfrune.c @@ -0,0 +1,29 @@ +#include "lib9.h" + +char* +utfrune(char *s, long c) +{ + long c1; + Rune r; + int n; + + if(c < Runesync) /* not part of utf sequence */ + return strchr(s, c); + + for(;;) { + c1 = *(uchar*)s; + if(c1 < Runeself) { /* one byte rune */ + if(c1 == 0) + return 0; + if(c1 == c) + return s; + s++; + continue; + } + n = chartorune(&r, s); + if(r == c) + return s; + s += n; + } + return 0; +} |
