Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
3.4 KiB

  1. /*++
  2. Copyright (C) 1999-2001 Microsoft Corporation
  3. Module Name:
  4. STRUTILS.H
  5. Abstract:
  6. String utilities
  7. History:
  8. --*/
  9. #ifndef __WBEM_STRING_UTILS__H_
  10. #define __WBEM_STRING_UTILS__H_
  11. #pragma optimize("gt", on)
  12. #include "os.h"
  13. #ifdef _DBG
  14. #define _DBG_BREAK DebugBreak();
  15. #else
  16. #define _DBG_BREAK
  17. #endif
  18. inline wchar_t ToLower(wchar_t c)
  19. {
  20. return OS::ToLower(c);
  21. }
  22. inline wchar_t ToUpper(wchar_t c)
  23. {
  24. return OS::ToUpper(c);
  25. }
  26. inline wchar_t wbem_towlower(wchar_t c)
  27. {
  28. if(c >= 0 && c <= 127)
  29. {
  30. if(c >= 'A' && c <= 'Z')
  31. return c + ('a' - 'A');
  32. else
  33. return c;
  34. }
  35. else return ToLower(c);
  36. }
  37. inline wchar_t wbem_towupper(wchar_t c)
  38. {
  39. if(c >= 0 && c <= 127)
  40. {
  41. if(c >= 'a' && c <= 'z')
  42. return c + ('A' - 'a');
  43. else
  44. return c;
  45. }
  46. else return ToUpper(c);
  47. }
  48. inline int wbem_wcsicmp( const wchar_t* wsz1, const wchar_t* wsz2)
  49. {
  50. while(*wsz1 || *wsz2)
  51. {
  52. int diff = wbem_towlower(*wsz1) - wbem_towlower(*wsz2);
  53. if(diff) return diff;
  54. wsz1++; wsz2++;
  55. }
  56. return 0;
  57. }
  58. inline int wbem_unaligned_wcsicmp( UNALIGNED const wchar_t* wsz1, UNALIGNED const wchar_t* wsz2)
  59. {
  60. while(*wsz1 || *wsz2)
  61. {
  62. int diff = wbem_towlower(*wsz1) - wbem_towlower(*wsz2);
  63. if(diff) return diff;
  64. wsz1++; wsz2++;
  65. }
  66. return 0;
  67. }
  68. // just like wcsicmp, but first 0 of unicode chracters have been omitted
  69. inline int wbem_ncsicmp(const char* wsz1, const char* wsz2)
  70. {
  71. while(*wsz1 || *wsz2)
  72. {
  73. int diff = wbem_towlower((unsigned char)*wsz1) -
  74. wbem_towlower((unsigned char)*wsz2);
  75. if(diff) return diff;
  76. wsz1++; wsz2++;
  77. }
  78. return 0;
  79. }
  80. inline int wbem_wcsnicmp( const wchar_t* wsz1, const wchar_t* wsz2, size_t n )
  81. {
  82. while(n-- && (*wsz1 || *wsz2))
  83. {
  84. int diff = wbem_towlower(*wsz1) - wbem_towlower(*wsz2);
  85. if(diff) return diff;
  86. wsz1++; wsz2++;
  87. }
  88. return 0;
  89. }
  90. inline int wbem_unaligned_wcsnicmp( UNALIGNED const wchar_t* wsz1, UNALIGNED const wchar_t* wsz2, size_t n )
  91. {
  92. while(n-- && (*wsz1 || *wsz2))
  93. {
  94. int diff = wbem_towlower(*wsz1) - wbem_towlower(*wsz2);
  95. if(diff) return diff;
  96. wsz1++; wsz2++;
  97. }
  98. return 0;
  99. }
  100. inline int wbem_stricmp(const char* sz1, const char* sz2)
  101. {
  102. while(*sz1 || *sz2)
  103. {
  104. int diff = wbem_towlower(*sz1) - wbem_towlower(*sz2);
  105. if(diff) return diff;
  106. sz1++; sz2++;
  107. }
  108. return 0;
  109. }
  110. inline int wbem_strnicmp(const char* sz1, const char* sz2, size_t n)
  111. {
  112. while(n-- && (*sz1 || *sz2))
  113. {
  114. int diff = wbem_towlower(*sz1) - wbem_towlower(*sz2);
  115. if(diff) return diff;
  116. sz1++; sz2++;
  117. }
  118. return 0;
  119. }
  120. inline bool wbem_iswdigit(wchar_t c)
  121. {
  122. return OS::wbem_iswdigit(c);
  123. };
  124. inline bool wbem_iswalnum (wchar_t c)
  125. {
  126. return OS::wbem_iswalnum(c);
  127. };
  128. //
  129. // returns the real length or Max + 1 if it exceeds
  130. // useful for not probing the entire string to see that it's too big
  131. //
  132. /////////////////////////////////////////
  133. inline size_t wcslen_max(WCHAR * p, size_t Max)
  134. {
  135. WCHAR * pBegin = p;
  136. WCHAR * pTail = p + Max + 1;
  137. while (*p && (p < pTail)) p++;
  138. return p-pBegin;
  139. };
  140. #pragma optimize("", on)
  141. #endif