X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fc-strstr.c;h=307c1f96aaeeed0acb8a0f1b1a9bd631f3094381;hb=1a6fbdd7d28dff1868c5eb0baf0029b27e42526a;hp=b015a6336e1acd2d1528bb863bb38e6fc3931215;hpb=e5cf463ba47a430a4a2509e029222682f974499f;p=gnulib.git diff --git a/lib/c-strstr.c b/lib/c-strstr.c index b015a6336..307c1f96a 100644 --- a/lib/c-strstr.c +++ b/lib/c-strstr.c @@ -1,28 +1,19 @@ -/* Copyright (C) 1994, 1999, 2002-2003, 2005-2006 Free Software Foundation, Inc. -This file is part of the GNU C Library. +/* c-strstr.c -- substring search in C locale + Copyright (C) 2005-2011 Free Software Foundation, Inc. + Written by Bruno Haible , 2005, 2007. -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software Foundation, -Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -/* - * My personal strstr() implementation that beats most other algorithms. - * Until someone tells me otherwise, I assume that this is the - * fastest implementation of strstr() in C. - * I deliberately chose not to comment it. You should have at least - * as much fun trying to understand it, as I had to write it :-). - * - * Stephen R. van den Berg, berg@pool.informatik.rwth-aachen.de */ + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ #include @@ -31,88 +22,11 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include -typedef unsigned chartype; - +/* Find the first occurrence of NEEDLE in HAYSTACK. */ char * -c_strstr (const char *phaystack, const char *pneedle) +c_strstr (const char *haystack, const char *needle) { - register const unsigned char *haystack, *needle; - register chartype b, c; - - haystack = (const unsigned char *) phaystack; - needle = (const unsigned char *) pneedle; - - b = *needle; - if (b != '\0') - { - haystack--; /* possible ANSI violation */ - do - { - c = *++haystack; - if (c == '\0') - goto ret0; - } - while (c != b); - - c = *++needle; - if (c == '\0') - goto foundneedle; - ++needle; - goto jin; - - for (;;) - { - register chartype a; - register const unsigned char *rhaystack, *rneedle; - - do - { - a = *++haystack; - if (a == '\0') - goto ret0; - if (a == b) - break; - a = *++haystack; - if (a == '\0') - goto ret0; -shloop:; } - while (a != b); - -jin: a = *++haystack; - if (a == '\0') - goto ret0; - - if (a != c) - goto shloop; - - rhaystack = haystack-- + 1; - rneedle = needle; - a = *rneedle; - - if (*rhaystack == a) - do - { - if (a == '\0') - goto foundneedle; - ++rhaystack; - a = *++needle; - if (*rhaystack != a) - break; - if (a == '\0') - goto foundneedle; - ++rhaystack; - a = *++needle; - } - while (*rhaystack == a); - - needle = rneedle; /* took the register-poor approach */ - - if (a == '\0') - break; - } - } -foundneedle: - return (char *) haystack; -ret0: - return 0; + /* POSIX says that strstr() interprets the strings as byte sequences, not + as character sequences in the current locale. */ + return strstr (haystack, needle); }