Apparently, the runtime library doesn't have a case insensitive strstr function, so I had to write one myself.
I took the old one and just replaced everything with TCHARs.
Is there anything inheritly wrong with it?
I don't think it matters if I use _totlower or _totupper?
The SDK docs says:
"In order for tolower to give the expected results, __isascii and isupper must both return nonzero."
I tested it with some non-ASCII characters, and tolower returned the same character, so I hope that's ok.
Code:
TCHAR *_tcsistr( const TCHAR * str1,
const TCHAR * str2 ) {
TCHAR *cp = (TCHAR *)str1;
TCHAR *s1, *s2;
if (!*str2) {
return (TCHAR *)str1;
}
while (*cp) {
s1 = cp;
s2 = (TCHAR *)str2;
// Matching characters will return zero if they are subtracted
while ( *s1 && *s2 && !(_totlower(*s1) - _totlower(*s2)) ) {
s1++, s2++;
}
if (!*s2) {
return cp;
}
cp++;
}
return NULL;
}
Original runtime function:
Code:
char * __cdecl strstr (
const char * str1,
const char * str2
)
{
char *cp = (char *) str1;
char *s1, *s2;
if ( !*str2 )
return((char *)str1);
while (*cp)
{
s1 = cp;
s2 = (char *) str2;
while ( *s1 && *s2 && !(*s1-*s2) )
s1++, s2++;
if (!*s2)
return(cp);
cp++;
}
return(NULL);
}