2012-03-12 665 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