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.

92 lines
2.2 KiB

  1. /***
  2. *wcsnicmp.c - compare n chars of wide-character strings, ignoring case
  3. *
  4. * Copyright (c) 1985-1992, 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. * 06-02-93 SRW ignore _INTL if _NTSUBSET_ defined.
  15. *
  16. *******************************************************************************/
  17. #include <windows.h>
  18. #include <cruntime.h>
  19. #include <string.h>
  20. #include <ctype.h>
  21. #include <locale.h>
  22. #ifdef _INTL
  23. #include <setlocal.h>
  24. #include <os2dll.h>
  25. #endif
  26. /***
  27. *int _wcsnicmp(first, last, count) - compares count wchar_t of strings,
  28. * ignore case
  29. *
  30. *Purpose:
  31. * Compare the two strings for lexical order. Stops the comparison
  32. * when the following occurs: (1) strings differ, (2) the end of the
  33. * strings is reached, or (3) count characters have been compared.
  34. * For the purposes of the comparison, upper case characters are
  35. * converted to lower case (wide-characters).
  36. *
  37. * *** NOTE: the comparison should be done in a neutral locale,
  38. * provided by the NLSAPI. Currently, the comparison is done
  39. * in the C locale. ***
  40. *
  41. *Entry:
  42. * wchar_t *first, *last - strings to compare
  43. * size_t count - maximum number of characters to compare
  44. *
  45. *Exit:
  46. * -1 if first < last
  47. * 0 if first == last
  48. * 1 if first > last
  49. * This range of return values may differ from other *cmp/*coll functions.
  50. *
  51. *Exceptions:
  52. *
  53. *******************************************************************************/
  54. int _CALLTYPE1 _wcsnicmp (
  55. const wchar_t * first,
  56. const wchar_t * last,
  57. size_t count
  58. )
  59. {
  60. wchar_t f,l;
  61. int result = 0;
  62. if (count)
  63. {
  64. #if defined(_INTL) && !defined(_NTSUBSET_)
  65. _mlock (_LC_CTYPE_LOCK);
  66. #endif
  67. do
  68. {
  69. f = iswupper(*first)
  70. ? *first - (wchar_t)L'A' + (wchar_t)L'a'
  71. : *first;
  72. l = iswupper(*last)
  73. ? *last - (wchar_t)L'A' + (wchar_t)L'a'
  74. : *last;
  75. first++;
  76. last++;
  77. } while (--count && f && l && f == l);
  78. #if defined(_INTL) && !defined(_NTSUBSET_)
  79. _munlock (_LC_CTYPE_LOCK);
  80. #endif
  81. result = (int)(f - l);
  82. }
  83. return result ;
  84. }