xref: /inferno-os/libkern/utfrune.c (revision 3cd4f1d15146c08f05206d6328ecbc1c7fdc8dfa)
1 #include "lib9.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 }
29