2012-03-12 96 views
3

有谁知道如何使用wcsstr而不区分大小写?如果这一点很重要,我会在内核驱动中使用它。Wcsstr无区分大小写

+0

内核的什么部分应该对这个库函数调用做出响应? – 2012-03-12 12:20:24

+0

有[一些](http://www.daniweb.com/software-development/c/code/216564)[示例](http://www.codeguru.com/cpp/cpp/string/article.php/c5641)如果您正确搜索。虽然我没有找到任何使用'whcar_t',它不应该很难修改它们来支持它。 – 2012-03-12 12:29:15

回答

4

如果你在Windows下编程,你可以使用StrStrI()函数。

你不能在内核驱动程序中使用它,所以你必须write it by your own。在该示例中,toupper()被使用并应该被替换为RtlUpcaseUnicodeChar(正如Rup指出的那样)。总结一下,你需要这样的东西:

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; 
} 
+0

['StrStrI'](http://msdn.microsoft.com/en-us/library/windows/desktop/bb773439.aspx)位于内核驱动程序无法使用的shlwapi中。但是,是的,你自己的代码可能是做的,尽管我怀疑'toupper'在这里也不可用。 – Rup 2012-03-12 12:57:30

+0

其实我回过头来看 - 有['RtlUpcaseUnicodeChar'](http://msdn.microsoft.com/en-us/library/windows/hardware/ff563003.aspx) – Rup 2012-03-12 13:03:23