]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libc/port/utfutf.c
libregexp: improve the transition to next available thread, instruction, and generation
[plan9front.git] / sys / src / libc / port / utfutf.c
1 #include <u.h>
2 #include <libc.h>
3
4
5 /*
6  * Return pointer to first occurrence of s2 in s1,
7  * 0 if none
8  */
9 char*
10 utfutf(char *s1, char *s2)
11 {
12         char *p;
13         long f, n1, n2;
14         Rune r;
15
16         n1 = chartorune(&r, s2);
17         f = r;
18         if(f <= Runesync)               /* represents self */
19                 return strstr(s1, s2);
20
21         n2 = strlen(s2);
22         for(p=s1; p=utfrune(p, f); p+=n1)
23                 if(strncmp(p, s2, n2) == 0)
24                         return p;
25         return 0;
26 }