xref: /plan9/sys/src/cmd/unix/u9fs/utfrune.c (revision 9a747e4fd48b9f4522c70c07e8f882a15030f964)
1 #include <plan9.h>
2 
3 char*
utfrune(char * s,long c)4 utfrune(char *s, long c)
5 {
6 	long c1;
7 	Rune r;
8 	int n;
9 
10 	if(c < Runesync)		/* not part of utf sequence */
11 		return strchr(s, c);
12 
13 	for(;;) {
14 		c1 = *(uchar*)s;
15 		if(c1 < Runeself) {	/* one byte rune */
16 			if(c1 == 0)
17 				return 0;
18 			if(c1 == c)
19 				return s;
20 			s++;
21 			continue;
22 		}
23 		n = chartorune(&r, s);
24 		if(r == c)
25 			return s;
26 		s += n;
27 	}
28 	return 0;
29 }
30