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.

112 lines
3.6 KiB

  1. /***
  2. *wcsnicmp.c - compare n chars of wide-character strings, ignoring case
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines _wcsnicmp() - Compares at most n characters of two wchar_t
  8. * strings, without regard to case.
  9. *
  10. *Revision History:
  11. * 09-09-91 ETC Created from strnicmp.c and wcsicmp.c.
  12. * 12-09-91 ETC Use C for neutral locale.
  13. * 04-07-92 KRS Updated and ripped out _INTL switches.
  14. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  15. * 04-14-93 CFW Remove locale-sensitive portion.
  16. * 09-07-93 GJF Fixed bug introduced on 4-14 (return value not was
  17. * not well-defined if count == 0).
  18. * 02-07-94 CFW POSIXify.
  19. * 09-06-94 CFW Remove _INTL switch.
  20. * 10-25-94 GJF Now works in non-C locales.
  21. * 09-26-95 GJF New locking macro, and scheme, for functions which
  22. * reference the locale.
  23. * 10-11-95 BWT Fix NTSUBSET
  24. * 08-27-98 GJF Revised multithread support based on threadlocinfo
  25. * struct.
  26. *
  27. *******************************************************************************/
  28. #ifndef _POSIX_
  29. #include <cruntime.h>
  30. #include <string.h>
  31. #include <ctype.h>
  32. #include <locale.h>
  33. #include <setlocal.h>
  34. #include <mtdll.h>
  35. /***
  36. *int _wcsnicmp(first, last, count) - compares count wchar_t of strings,
  37. * ignore case
  38. *
  39. *Purpose:
  40. * Compare the two strings for lexical order. Stops the comparison
  41. * when the following occurs: (1) strings differ, (2) the end of the
  42. * strings is reached, or (3) count characters have been compared.
  43. * For the purposes of the comparison, upper case characters are
  44. * converted to lower case (wide-characters).
  45. *
  46. *Entry:
  47. * wchar_t *first, *last - strings to compare
  48. * size_t count - maximum number of characters to compare
  49. *
  50. *Exit:
  51. * -1 if first < last
  52. * 0 if first == last
  53. * 1 if first > last
  54. * This range of return values may differ from other *cmp/*coll functions.
  55. *
  56. *Exceptions:
  57. *
  58. *******************************************************************************/
  59. int __cdecl _wcsnicmp (
  60. const wchar_t * first,
  61. const wchar_t * last,
  62. size_t count
  63. )
  64. {
  65. wchar_t f,l;
  66. int result = 0;
  67. #ifdef _MT
  68. pthreadlocinfo ptloci = _getptd()->ptlocinfo;
  69. if ( ptloci != __ptlocinfo )
  70. ptloci = __updatetlocinfo();
  71. #endif
  72. if ( count ) {
  73. #ifndef _NTSUBSET_
  74. #ifdef _MT
  75. if ( ptloci->lc_handle[LC_CTYPE] == _CLOCALEHANDLE ) {
  76. #else
  77. if ( __lc_handle[LC_CTYPE] == _CLOCALEHANDLE ) {
  78. #endif
  79. #endif /* _NTSUBSET_ */
  80. do {
  81. f = __ascii_towlower(*first);
  82. l = __ascii_towlower(*last);
  83. first++;
  84. last++;
  85. } while ( (--count) && f && (f == l) );
  86. #ifndef _NTSUBSET_
  87. }
  88. else {
  89. do {
  90. #ifdef _MT
  91. f = __towlower_mt( ptloci, (unsigned short)(*(first++)) );
  92. l = __towlower_mt( ptloci, (unsigned short)(*(last++)) );
  93. #else
  94. f = towlower( (unsigned short)(*(first++)) );
  95. l = towlower( (unsigned short)(*(last++)) );
  96. #endif
  97. } while ( (--count) && f && (f == l) );
  98. }
  99. #endif /* _NTSUBSET_ */
  100. result = (int)(f - l);
  101. }
  102. return result;
  103. }
  104. #endif /* _POSIX_ */