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.

195 lines
6.0 KiB

  1. #include "npcommon.h"
  2. #ifdef strcmpf
  3. #undef strcmpf
  4. int WINAPI strcmpf(LPCSTR lpStr1, LPCSTR lpStr2)
  5. {
  6. return lstrcmp(lpStr1, lpStr2);
  7. }
  8. #else
  9. // strcmpf(str1, str2)
  10. //
  11. // Returns -1 if str1 is lexically less than str2
  12. // Returns 0 if str1 is equal to str2
  13. // Returns 1 if str1 is lexically greater than str2
  14. int WINAPI strcmpf(LPCSTR lpStr1, LPCSTR lpStr2)
  15. {
  16. for (; *lpStr1 && *lpStr2; ADVANCE(lpStr1), ADVANCE(lpStr2)) {
  17. UINT ch1, ch2;
  18. UINT nCmp;
  19. // for same-width chars, compare straight;
  20. // for DBC vs. SBC, compare 0xttll against 0x00ss
  21. ch1 = IS_LEAD_BYTE(*lpStr1) ? GetTwoByteChar(lpStr1) : *lpStr1;
  22. ch2 = IS_LEAD_BYTE(*lpStr2) ? GetTwoByteChar(lpStr2) : *lpStr2;
  23. if (ch1 > 0xff || ch2 > 0xff)
  24. nCmp = (ch1 < ch2) ? -1 : ((ch1 == ch2) ? 0 : 1);
  25. else
  26. {
  27. if (CollateTable[ch1] == CollateTable[ch2])
  28. nCmp = (ch1 < ch2) ? -1 : ((ch1 == ch2) ? 0 : 1);
  29. else
  30. nCmp = (CollateTable[ch1] < CollateTable[ch2]) ? -1 : 1;
  31. }
  32. if (nCmp != 0)
  33. return nCmp;
  34. }
  35. // end of one string or the other. if different lengths,
  36. // shorter one must be lexically less, so it's ok to just
  37. // compare bytes.
  38. return (*lpStr1 > *lpStr2) ? -1 : (*lpStr1 == *lpStr2) ? 0 : 1;
  39. }
  40. #endif /* ifndef strcmpf */
  41. #ifdef stricmpf
  42. #undef stricmpf
  43. int WINAPI stricmpf(LPCSTR lpStr1, LPCSTR lpStr2)
  44. {
  45. return lstrcmpi(lpStr1, lpStr2);
  46. }
  47. #else
  48. // stricmpf(str1, str2)
  49. //
  50. // Returns -1 if str1 is lexically less than str2
  51. // Returns 0 if str1 is equal to str2
  52. // Returns 1 if str1 is lexically greater than str2
  53. // All comparisons are case-insensitive
  54. int WINAPI stricmpf(LPCSTR lpStr1, LPCSTR lpStr2)
  55. {
  56. for (; *lpStr1 && *lpStr2; ADVANCE(lpStr1), ADVANCE(lpStr2)) {
  57. UINT ch1, ch2;
  58. UINT nCmp;
  59. // for same-width chars, compare straight;
  60. // for DBC vs. SBC, compare 0xttll against 0x00ss
  61. ch1 = IS_LEAD_BYTE(*lpStr1) ? GetTwoByteChar(lpStr1) : *lpStr1;
  62. ch2 = IS_LEAD_BYTE(*lpStr2) ? GetTwoByteChar(lpStr2) : *lpStr2;
  63. if (ch1 > 0xff || ch2 > 0xff)
  64. nCmp = (ch1 < ch2) ? -1 : ((ch1 == ch2) ? 0 : 1);
  65. else
  66. {
  67. ch1 = ToUpperCaseTable[ch1];
  68. ch2 = ToUpperCaseTable[ch2];
  69. if (CollateTable[ch1] == CollateTable[ch2])
  70. nCmp = 0;
  71. else
  72. nCmp = (CollateTable[ch1] < CollateTable[ch2]) ? -1 : 1;
  73. }
  74. if (nCmp != 0)
  75. return nCmp;
  76. }
  77. // end of one string or the other. if different lengths,
  78. // shorter one must be lexically less, so it's ok to just
  79. // compare bytes.
  80. return (*lpStr1 > *lpStr2) ? -1 : (*lpStr1 == *lpStr2) ? 0 : 1;
  81. }
  82. #endif /* ifndef stricmpf */
  83. // strncmpf(str1, str2, cb)
  84. //
  85. // Returns -1 if str1 is lexically less than str2
  86. // Returns 0 if str1 is equal to str2
  87. // Returns 1 if str1 is lexically greater than str2
  88. // At most cb bytes are compared before returning
  89. int WINAPI strncmpf(LPCSTR lpStr1, LPCSTR lpStr2, UINT cb)
  90. {
  91. LPCSTR lp1 = lpStr1;
  92. for (; *lp1 && *lpStr2; ADVANCE(lp1), ADVANCE(lpStr2)) {
  93. UINT ch1, ch2;
  94. UINT nCmp;
  95. // see if we've reached the byte limit. only need
  96. // to compare one string for length, since if they
  97. // get out of sync (DBCS only), we will get a compare
  98. // error immediately.
  99. if ((UINT)(lp1 - lpStr1) >= cb)
  100. return 0; // no failures, reached limit
  101. // for same-width chars, compare straight;
  102. // for DBC vs. SBC, compare 0xttll against 0x00ss
  103. ch1 = IS_LEAD_BYTE(*lp1) ? GetTwoByteChar(lp1) : *lp1;
  104. ch2 = IS_LEAD_BYTE(*lpStr2) ? GetTwoByteChar(lpStr2) : *lpStr2;
  105. nCmp = (ch1 < ch2) ? -1 : ((ch1 == ch2) ? 0 : 1);
  106. if (nCmp != 0)
  107. return nCmp;
  108. }
  109. // end of one string or the other. check the length to see if
  110. // we have compared as many bytes as needed.
  111. if ((UINT)(lp1 - lpStr1) >= cb)
  112. return 0; // no failures, reached limit
  113. // end of one string or the other. if different lengths,
  114. // shorter one must be lexically less, so it's ok to just
  115. // compare bytes.
  116. return (*lp1 > *lpStr2) ? -1 : (*lp1 == *lpStr2) ? 0 : 1;
  117. }
  118. // strnicmpf(str1, str2, cb)
  119. //
  120. // Returns -1 if str1 is lexically less than str2
  121. // Returns 0 if str1 is equal to str2
  122. // Returns 1 if str1 is lexically greater than str2
  123. // All comparisons are case-insensitive
  124. // At most cb bytes are compared
  125. int WINAPI strnicmpf(LPCSTR lpStr1, LPCSTR lpStr2, UINT cb)
  126. {
  127. LPCSTR lp1 = lpStr1;
  128. for (; *lp1 && *lpStr2; ADVANCE(lp1), ADVANCE(lpStr2)) {
  129. UINT ch1, ch2;
  130. UINT nCmp;
  131. // see if we've reached the byte limit. only need
  132. // to compare one string for length, since if they
  133. // get out of sync (DBCS only), we will get a compare
  134. // error immediately.
  135. if ((UINT)(lp1 - lpStr1) >= cb)
  136. return 0; // no failures, reached limit
  137. // for same-width chars, compare straight;
  138. // for DBC vs. SBC, compare 0xttll against 0x00ss
  139. ch1 = IS_LEAD_BYTE(*lp1) ? GetTwoByteChar(lp1) : PtrToUlong(CharUpper((LPTSTR) *((BYTE *)lp1)));
  140. ch2 = IS_LEAD_BYTE(*lpStr2) ? GetTwoByteChar(lpStr2) : PtrToUlong(CharUpper((LPTSTR) *((BYTE *)lpStr2)));
  141. nCmp = (ch1 < ch2) ? -1 : ((ch1 == ch2) ? 0 : 1);
  142. if (nCmp != 0)
  143. return nCmp;
  144. }
  145. // end of one string or the other. check the length to see if
  146. // we have compared as many bytes as needed.
  147. if ((UINT)(lp1 - lpStr1) >= cb)
  148. return 0; // no failures, reached limit
  149. // end of one string or the other. if different lengths,
  150. // shorter one must be lexically less, so it's ok to just
  151. // compare bytes.
  152. return (*lp1 > *lpStr2) ? -1 : (*lp1 == *lpStr2) ? 0 : 1;
  153. }