summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2024-11-28 10:03:50 -0500
committerWilliam Wilgus <wilgus.william@gmail.com>2024-11-28 15:07:55 -0500
commitafb0e845cfafa3a22867e54bd737d4cfd7eb1506 (patch)
treedaca12999997abc49d9a145ed4153962b24e4bcb
parent12aea7dae6c968771cb9e18e5e54583dce5fe61d (diff)
downloadrockbox-afb0e845cf.tar.gz
rockbox-afb0e845cf.zip
strcasestr smaller function for PREFER_SIZE_OVER_SPEED
tester script: https://onlinegdb.com/TbILrA5E7 Change-Id: Ie5a37db13500510e30e87a20782f13adfe2b4d78
-rw-r--r--firmware/common/strcasestr.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/firmware/common/strcasestr.c b/firmware/common/strcasestr.c
index 095eebdd66..a20951d877 100644
--- a/firmware/common/strcasestr.c
+++ b/firmware/common/strcasestr.c
@@ -33,7 +33,48 @@
#include <ctype.h>
typedef unsigned chartype;
-
+#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
+char* strcasestr (const char* haystack, const char* needle)
+{
+ chartype needle_ch = tolower(*needle++);
+ chartype needle_upch = toupper(needle_ch);
+ chartype ch_h;
+ char* match = (char*)haystack; /* if needle empty return haystack */
+
+ if (needle_ch != 0) {
+ /* 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 = (char*) haystack - 1;
+ /* find the first non-matching character */
+lcase_match:
+ while (ch_h == needle_ch) {
+ ch_h = *haystack++;
+ needle_ch = tolower(*needle++);
+ if (needle_ch == 0) /* end of needle, found match.. */
+ return match;
+ }
+/* lcase or ucase match */
+ needle_upch = toupper(needle_ch);
+ while (ch_h == needle_upch || ch_h == needle_ch) {
+ ch_h = *haystack++;
+ needle_ch = tolower(*needle++);
+ if (needle_ch == 0) /* end of needle, found match.. */
+ return match;
+
+ if (ch_h == needle_ch)
+ goto lcase_match;
+ needle_upch = toupper(needle_ch);
+ }
+ match = NULL;
+ }
+ return match;
+}
+#else
char* strcasestr (const char* phaystack, const char* pneedle)
{
const unsigned char *haystack, *needle;
@@ -120,3 +161,4 @@ char* strcasestr (const char* phaystack, const char* pneedle)
ret0:
return 0;
}
+#endif