utfrune.c 375 B

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