runestrstr.c 397 B

1234567891011121314151617181920212223242526272829
  1. #include <u.h>
  2. #include <libc.h>
  3. /*
  4. * Return pointer to first occurrence of s2 in s1,
  5. * 0 if none
  6. */
  7. Rune*
  8. runestrstr(Rune *s1, Rune *s2)
  9. {
  10. Rune *p, *pa, *pb;
  11. int c0, c;
  12. c0 = *s2;
  13. if(c0 == 0)
  14. return s1;
  15. s2++;
  16. for(p=runestrchr(s1, c0); p; p=runestrchr(p+1, c0)) {
  17. pa = p;
  18. for(pb=s2;; pb++) {
  19. c = *pb;
  20. if(c == 0)
  21. return p;
  22. if(c != *++pa)
  23. break;
  24. }
  25. }
  26. return 0;
  27. }