utfrune.c 390 B

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