]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libc/port/utfnlen.c
libregexp: improve the transition to next available thread, instruction, and generation
[plan9front.git] / sys / src / libc / port / utfnlen.c
1 #include <u.h>
2 #include <libc.h>
3
4 int
5 utfnlen(char *s, long m)
6 {
7         int c;
8         long n;
9         Rune rune;
10         char *es;
11
12         es = s + m;
13         for(n = 0; s < es; n++) {
14                 c = *(uchar*)s;
15                 if(c < Runeself){
16                         if(c == '\0')
17                                 break;
18                         s++;
19                         continue;
20                 }
21                 if(!fullrune(s, es-s))
22                         break;
23                 s += chartorune(&rune, s);
24         }
25         return n;
26 }