xref: /plan9/sys/src/cmd/unix/drawterm/libc/utfnlen.c (revision 8ccd4a6360d974db7bd7bbd4f37e7018419ea908)
1 #include <u.h>
2 #include <libc.h>
3 
4 int
utfnlen(char * s,long m)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 }
27