utflen.c 231 B

12345678910111213141516171819202122
  1. #include <u.h>
  2. #include <libc.h>
  3. int
  4. utflen(char *s)
  5. {
  6. int c;
  7. long n;
  8. Rune rune;
  9. n = 0;
  10. for(;;) {
  11. c = *(uchar*)s;
  12. if(c < Runeself) {
  13. if(c == 0)
  14. return n;
  15. s++;
  16. } else
  17. s += chartorune(&rune, s);
  18. n++;
  19. }
  20. }