runestrstr.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. /*
  10. * The authors of this software are Rob Pike and Ken Thompson.
  11. * Copyright (c) 2002 by Lucent Technologies.
  12. * Permission to use, copy, modify, and distribute this software for any
  13. * purpose without fee is hereby granted, provided that this entire notice
  14. * is included in all copies of any software which is or includes a copy
  15. * or modification of this software and in all copies of the supporting
  16. * documentation for such software.
  17. * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
  18. * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY
  19. * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
  20. * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
  21. */
  22. #include <stdarg.h>
  23. #include <string.h>
  24. #include "utf.h"
  25. #include "utfdef.h"
  26. /*
  27. * Return pointer to first occurrence of s2 in s1,
  28. * 0 if none
  29. */
  30. Rune*
  31. runestrstr(Rune *s1, Rune *s2)
  32. {
  33. Rune *p, *pa, *pb;
  34. int c0, c;
  35. c0 = *s2;
  36. if(c0 == 0)
  37. return s1;
  38. s2++;
  39. for(p=runestrchr(s1, c0); p; p=runestrchr(p+1, c0)) {
  40. pa = p;
  41. for(pb=s2;; pb++) {
  42. c = *pb;
  43. if(c == 0)
  44. return p;
  45. if(c != *++pa)
  46. break;
  47. }
  48. }
  49. return 0;
  50. }