1 /* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
20 * The original strstr() file contains the following comment:
22 * My personal strstr() implementation that beats most other algorithms.
23 * Until someone tells me otherwise, I assume that this is the
24 * fastest implementation of strstr() in C.
25 * I deliberately chose not to comment it. You should have at least
26 * as much fun trying to understand it, as I had to write it :-).
28 * Stephen R. van den Berg, berg@pool.informatik.rwth-aachen.de */
33 wcsstr (haystack, needle)
34 const wchar_t *haystack;
35 const wchar_t *needle;
37 register wchar_t b, c;
39 if ((b = *needle) != L'\0')
41 haystack--; /* possible ANSI violation */
43 if ((c = *++haystack) == L'\0')
55 register const wchar_t *rhaystack, *rneedle;
59 if (!(a = *++haystack))
63 if ((a = *++haystack) == L'\0')
69 jin: if (!(a = *++haystack))
75 if (*(rhaystack = haystack-- + 1) == (a = *(rneedle = needle)))
80 if (*++rhaystack != (a = *++needle))
85 while (*++rhaystack == (a = *++needle));
87 needle = rneedle; /* took the register-poor approach */
94 return (wchar_t*) haystack;
98 /* This alias is for backward compatibility with drafts of the ISO C
99 standard. Unfortunately the Unix(TM) standard requires this name. */
100 weak_alias (wcsstr, wcswcs)