diff options
author | William Wilgus <wilgus.william@gmail.com> | 2024-12-31 23:03:32 -0500 |
---|---|---|
committer | William Wilgus <wilgus.william@gmail.com> | 2024-12-31 23:06:08 -0500 |
commit | e79996e031ada89b2050b6974027d439e73020c6 (patch) | |
tree | d7bf27395bab9a44aae8ef17afebfe14a99c3246 | |
parent | 44e36aba94ddec08d5a185994b6164ebdcacdea2 (diff) | |
download | rockbox-e79996e031.tar.gz rockbox-e79996e031.zip |
[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
-rw-r--r-- | firmware/common/strcasestr.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/firmware/common/strcasestr.c b/firmware/common/strcasestr.c index 44269b58ee..f8a2093322 100644 --- a/firmware/common/strcasestr.c +++ b/firmware/common/strcasestr.c @@ -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 |