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.

145 lines
2.8 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. /*
  13. inline int wbem_towlower(wint_t c)
  14. {
  15. if(c >= 0 && c <= 127)
  16. {
  17. if(c >= 'A' && c <= 'Z')
  18. return c + ('a' - 'A');
  19. else
  20. return c;
  21. }
  22. else return towlower(c);
  23. }
  24. */
  25. #define wbem_towlower(C) \
  26. (((C) >= 0 && (C) <= 127)? \
  27. (((C) >= 'A' && (C) <= 'Z')? \
  28. ((C) + ('a' - 'A')): \
  29. (C) \
  30. ): \
  31. towlower(C) \
  32. )
  33. inline int wbem_towupper(wint_t c)
  34. {
  35. if(c >= 0 && c <= 127)
  36. {
  37. if(c >= 'a' && c <= 'z')
  38. return c + ('A' - 'a');
  39. else
  40. return c;
  41. }
  42. else return towupper(c);
  43. }
  44. inline int wbem_tolower(int c)
  45. {
  46. if(c >= 0 && c <= 127)
  47. {
  48. if(c >= 'A' && c <= 'Z')
  49. return c + ('a' - 'A');
  50. else
  51. return c;
  52. }
  53. else return tolower(c);
  54. }
  55. inline int wbem_toupper(int c)
  56. {
  57. if(c >= 0 && c <= 127)
  58. {
  59. if(c >= 'a' && c <= 'z')
  60. return c + ('A' - 'a');
  61. else
  62. return c;
  63. }
  64. else return toupper(c);
  65. }
  66. inline int wbem_wcsicmp(const wchar_t* wsz1, const wchar_t* wsz2)
  67. {
  68. while(*wsz1 || *wsz2)
  69. {
  70. int diff = wbem_towlower(*wsz1) - wbem_towlower(*wsz2);
  71. if(diff) return diff;
  72. wsz1++; wsz2++;
  73. }
  74. return 0;
  75. }
  76. // just like wcsicmp, but first 0 of unicode chracters have been omitted
  77. inline int wbem_ncsicmp(const char* wsz1, const char* wsz2)
  78. {
  79. while(*wsz1 || *wsz2)
  80. {
  81. int diff = wbem_towlower((unsigned char)*wsz1) -
  82. wbem_towlower((unsigned char)*wsz2);
  83. if(diff) return diff;
  84. wsz1++; wsz2++;
  85. }
  86. return 0;
  87. }
  88. inline int wbem_wcsnicmp(const wchar_t* wsz1, const wchar_t* wsz2, size_t n)
  89. {
  90. while(n-- && (*wsz1 || *wsz2))
  91. {
  92. int diff = wbem_towlower(*wsz1) - wbem_towlower(*wsz2);
  93. if(diff) return diff;
  94. wsz1++; wsz2++;
  95. }
  96. return 0;
  97. }
  98. inline int wbem_stricmp(const char* sz1, const char* sz2)
  99. {
  100. while(*sz1 || *sz2)
  101. {
  102. int diff = wbem_tolower(*sz1) - wbem_tolower(*sz2);
  103. if(diff) return diff;
  104. sz1++; sz2++;
  105. }
  106. return 0;
  107. }
  108. inline int wbem_strnicmp(const char* sz1, const char* sz2, size_t n)
  109. {
  110. while(n-- && (*sz1 || *sz2))
  111. {
  112. int diff = wbem_tolower(*sz1) - wbem_tolower(*sz2);
  113. if(diff) return diff;
  114. sz1++; sz2++;
  115. }
  116. return 0;
  117. }
  118. #pragma optimize("", off)
  119. #endif