forked from len0rd/rockbox
[Bugfix] strcasestr
I pushed the wrong version of the function it was an experiment on resetting haystack past the searched string but it is missing the rest of the logic and therefore misses strings that should match Change-Id: I23391d2e753840bfeaab8e26d9987198272fe7b8
This commit is contained in:
parent
44e36aba94
commit
e79996e031
1 changed files with 10 additions and 10 deletions
|
@ -37,24 +37,25 @@ typedef unsigned chartype;
|
|||
char* strcasestr (const char* haystack, const char* needle)
|
||||
{
|
||||
const char* match, *needle_search;
|
||||
chartype needle_ch, needle_upch, ch_h;
|
||||
|
||||
chartype needle_ch, ch_h;
|
||||
chartype first_ch, first_upch;
|
||||
if (*needle == 0) /* if needle empty return haystack */
|
||||
return (char*)haystack;
|
||||
|
||||
first_ch = tolower(*needle++); /*store first & step to 2nd needle character */
|
||||
first_upch = toupper(first_ch);
|
||||
|
||||
while(1)
|
||||
{
|
||||
needle_search = needle;
|
||||
needle_ch = tolower(*needle_search++);
|
||||
needle_upch = toupper(needle_ch);
|
||||
/* find the first matching character */
|
||||
do
|
||||
{
|
||||
ch_h = *haystack++;
|
||||
if (ch_h == 0) /* end of haystack no match.. */
|
||||
return NULL;
|
||||
} while (ch_h != needle_ch && ch_h != needle_upch);
|
||||
match = haystack;
|
||||
} while (ch_h != first_ch && ch_h != first_upch);
|
||||
match = haystack; /* keep progress thru haystack */
|
||||
needle_search = needle; /* reset needle to second character */
|
||||
goto case_match;
|
||||
|
||||
/* find the first non-matching character */
|
||||
|
@ -66,10 +67,9 @@ case_match:
|
|||
if (needle_ch == 0) /* end of needle, found match.. */
|
||||
return (char*)haystack - 1;
|
||||
}
|
||||
needle_upch = toupper(needle_ch);
|
||||
if (ch_h == needle_upch)
|
||||
needle_ch = toupper(needle_ch);
|
||||
if (ch_h == needle_ch)
|
||||
goto case_match;
|
||||
haystack = match;
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue