Commit a0067415 authored by rswindell's avatar rswindell
Browse files

The Win32 implementation of strcasestr() defined here is currently very

heavy-handed (performs strdup/malloc's and modifications of the strings),
so a temporary hack is to perform a case-sensitive search (using the standard
strstr() function) first. The results won't exactly match the traditional
strstr() and the performance improvement is only for positive matches
(where the correct case was guessed in the passed 'needle' string arg).
TODO: re-write or copy a good/fast strcasestr() implementation for Win32 builds.
parent 0e66b7eb
......@@ -80,13 +80,16 @@ int DLLCALL safe_snprintf(char *dst, size_t size, const char *fmt, ...)
#ifdef _MSC_VER
/* Case insensitive version of strstr() */
/* Case insensitive version of strstr() - currently heavy-handed */
char* DLLCALL strcasestr(const char* haystack, const char* needle)
char* p = NULL;
/* temporary performance hack begin (warning: different behavior from traditional strcasestr): */
if((p = strstr(haystack, needle)) != NULL)
return p;
char* h = strdup(haystack);
char* n = strdup(needle);
char* p = NULL;
if(h != NULL && n != NULL)
p = strstr(strupr(h), strupr(n));
int offset = p - h;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment