runestrstr.c 809 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. /*
  12. * Return pointer to first occurrence of s2 in s1,
  13. * 0 if none
  14. */
  15. Rune*
  16. runestrstr(Rune *s1, Rune *s2)
  17. {
  18. Rune *p, *pa, *pb;
  19. int c0, c;
  20. c0 = *s2;
  21. if(c0 == 0)
  22. return s1;
  23. s2++;
  24. for(p=runestrchr(s1, c0); p; p=runestrchr(p+1, c0)) {
  25. pa = p;
  26. for(pb=s2;; pb++) {
  27. c = *pb;
  28. if(c == 0)
  29. return p;
  30. if(c != *++pa)
  31. break;
  32. }
  33. }
  34. return 0;
  35. }