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