Wcsstr no case sensitivity
1 answer
If you are programming on Windows, you can use the function StrStrI()
.
You cannot use it in a kernel driver, so you need to write it down as you see fit . In this example is used toupper()
and should be replaced with RtlUpcaseUnicodeChar
(as pointed out by Rup). To summarize, you need something like this:
char *stristr(const wchar_t *String, const wchar_t *Pattern)
{
wchar_t *pptr, *sptr, *start;
for (start = (wchar_t *)String; *start != NUL; ++start)
{
while (((*start!=NUL) && (RtlUpcaseUnicodeChar(*start)
!= RtlUpcaseUnicodeChar(*Pattern))))
{
++start;
}
if (NUL == *start)
return NULL;
pptr = (wchar_t *)Pattern;
sptr = (wchar_t *)start;
while (RtlUpcaseUnicodeChar(*sptr) == RtlUpcaseUnicodeChar(*pptr))
{
sptr++;
pptr++;
if (NUL == *pptr)
return (start);
}
}
return NULL;
}
+4
source to share