Source code of Windows XP (NT5)
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.

130 lines
4.1 KiB

  1. /***
  2. *wcsicoll.c - Collate wide-character locale strings without regard to case
  3. *
  4. * Copyright (c) 1988-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Compare two wchar_t strings using the locale LC_COLLATE information
  8. * without regard to case.
  9. *
  10. *Revision History:
  11. * 10-16-91 ETC Created from wcscoll.c.
  12. * 12-08-91 ETC Added multithread lock.
  13. * 04-06-92 KRS Make work without _INTL also.
  14. * 09-02-92 SRW Get _INTL definition via ..\crt32.def
  15. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  16. * 04-14-93 CFW Error sets errno, cleanup.
  17. * 06-02-93 SRW ignore _INTL if _NTSUBSET_ defined.
  18. * 09-15-93 CFW Use ANSI conformant "__" names.
  19. * 09-22-93 CFW Use __crtxxx internal NLS API wrapper.
  20. * 09-29-93 GJF Merged NT SDK and Cuda versions.
  21. * 11-09-93 CFW Use LC_COLLATE code page for __crtxxx() conversion.
  22. * 02-07-94 CFW POSIXify.
  23. * 04-11-93 CFW Change NLSCMPERROR to _NLCMPERROR.
  24. * 09-06-94 CFW Remove _INTL switch.
  25. * 10-25-94 GJF Sped up C locale, multi-thread case.
  26. * 09-26-95 GJF New locking macro, and scheme, for functions which
  27. * reference the locale.
  28. * 10-30-95 GJF Specify SORT_STRINGSORT to CompareString.
  29. * 07-16-96 SKS Added missing call to _unlock_locale()
  30. * 11-24-97 GJF Removed bogus codepage determination.
  31. * 01-12-98 GJF Use _lc_collate_cp codepage.
  32. * 08-27-98 GJF Revised multithread support based on threadlocinfo
  33. * struct.
  34. *
  35. *******************************************************************************/
  36. #ifndef _POSIX_
  37. #include <cruntime.h>
  38. #include <windows.h>
  39. #include <stdlib.h>
  40. #include <string.h>
  41. #include <locale.h>
  42. #include <setlocal.h>
  43. #include <mtdll.h>
  44. #include <errno.h>
  45. #include <awint.h>
  46. /***
  47. *int _wcsicoll() - Collate wide-character locale strings without regard to case
  48. *
  49. *Purpose:
  50. * Compare two wchar_t strings using the locale LC_COLLATE information
  51. * without regard to case.
  52. * In the C locale, _wcsicmp() is used to make the comparison.
  53. *
  54. *Entry:
  55. * const wchar_t *s1 = pointer to the first string
  56. * const wchar_t *s2 = pointer to the second string
  57. *
  58. *Exit:
  59. * -1 = first string less than second string
  60. * 0 = strings are equal
  61. * 1 = first string greater than second string
  62. * This range of return values may differ from other *cmp/*coll functions.
  63. *
  64. *Exceptions:
  65. * _NLSCMPERROR = error
  66. * errno = EINVAL
  67. *
  68. *******************************************************************************/
  69. int __cdecl _wcsicoll (
  70. const wchar_t *_string1,
  71. const wchar_t *_string2
  72. )
  73. {
  74. #if !defined(_NTSUBSET_)
  75. int ret;
  76. wchar_t f, l;
  77. #ifdef _MT
  78. pthreadlocinfo ptloci = _getptd()->ptlocinfo;
  79. if ( ptloci != __ptlocinfo )
  80. ptloci = __updatetlocinfo();
  81. if ( ptloci->lc_handle[LC_COLLATE] == _CLOCALEHANDLE ) {
  82. #else
  83. if ( __lc_handle[LC_COLLATE] == _CLOCALEHANDLE ) {
  84. #endif
  85. do {
  86. f = __ascii_towlower(*_string1);
  87. l = __ascii_towlower(*_string2);
  88. _string1++;
  89. _string2++;
  90. } while ( (f) && (f == l) );
  91. return (int)(f - l);
  92. }
  93. #ifdef _MT
  94. if ( 0 == (ret = __crtCompareStringW( ptloci->lc_handle[LC_COLLATE],
  95. #else
  96. if ( 0 == (ret = __crtCompareStringW( __lc_handle[LC_COLLATE],
  97. #endif
  98. SORT_STRINGSORT | NORM_IGNORECASE,
  99. _string1,
  100. -1,
  101. _string2,
  102. -1,
  103. #ifdef _MT
  104. ptloci->lc_codepage )) )
  105. #else
  106. __lc_codepage )) )
  107. #endif
  108. {
  109. errno = EINVAL;
  110. return _NLSCMPERROR;
  111. }
  112. return (ret - 2);
  113. #else
  114. return _wcsicmp(_string1, _string2);
  115. #endif
  116. }
  117. #endif /* _POSIX_ */