]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libc/port/utfrrune.c
libregexp: improve the transition to next available thread, instruction, and generation
[plan9front.git] / sys / src / libc / port / utfrrune.c
1 #include <u.h>
2 #include <libc.h>
3
4 char*
5 utfrrune(char *s, long c)
6 {
7         long c1;
8         Rune r;
9         char *s1;
10
11         if(c < Runesync)                /* not part of utf sequence */
12                 return strrchr(s, c);
13
14         s1 = 0;
15         for(;;) {
16                 c1 = *(uchar*)s;
17                 if(c1 < Runeself) {     /* one byte rune */
18                         if(c1 == 0)
19                                 return s1;
20                         if(c1 == c)
21                                 s1 = s;
22                         s++;
23                         continue;
24                 }
25                 c1 = chartorune(&r, s);
26                 if(r == c)
27                         s1 = s;
28                 s += c1;
29         }
30 }