Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wcsstr no case sensitivity

Does anybody know how to use wcsstr with no case sensitivity on C? If this important I will use it in kernel driver.

like image 412
user1262425 Avatar asked Mar 12 '12 12:03

user1262425


Video Answer


1 Answers

If you're programming under Windows you can use the StrStrI() function.

You can't use it in a kernel driver so you have to write it by your own. In that example toupper() is used and should be replace 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;
}
like image 74
Adriano Repetti Avatar answered Sep 26 '22 15:09

Adriano Repetti