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.

63 lines
1.9 KiB

  1. /***
  2. *wcsnicmp.c - compare first n characters of two wide character strings with
  3. * case insensitivity
  4. *
  5. * Copyright (c) 1985-1988, Microsoft Corporation. All rights reserved.
  6. *
  7. *Purpose:
  8. * defines wcsnicmp() - compare first n characters of two wide character
  9. * strings for lexical order with case insensitivity.
  10. *
  11. *Revision History:
  12. * 04-07-91 IanJa C version created.
  13. * 11-25-91 AlexT Modified from wcsncmp.c
  14. * 04-Mar-92 ChrisMay fixed signed/unsigned warning in wcUP()
  15. * 12-Mar-92 Fixed bug in wcsnicmp (used to return *first - *last)
  16. *
  17. *******************************************************************************/
  18. #include <stdlib.h>
  19. /***
  20. *wchar_t wcUp(wc) - upper case wide character
  21. *
  22. */
  23. #define wcUp(wc) (('a' <= (wchar_t) (wc) && (wchar_t) (wc) <= 'z') ? \
  24. (wchar_t) (wc) + (wchar_t)('A' - 'a') : (wchar_t) (wc))
  25. /***
  26. *int wcsnicmp(first, last, count) - compare first count wide characters of wide
  27. * character strings with case insensitivity.
  28. *
  29. *Purpose:
  30. * Compares two wide character strings for lexical order. The comparison
  31. * stops after: (1) a difference between the strings is found, (2) the end
  32. * of the strings is reached, or (3) count characters have been
  33. * compared.
  34. *
  35. *Entry:
  36. * char *first, *last - wide character strings to compare
  37. * unsigned count - maximum number of wide characters to compare
  38. *
  39. *Exit:
  40. * returns <0 if first < last
  41. * returns 0 if first == last
  42. * returns >0 if first > last
  43. *
  44. *Exceptions:
  45. *
  46. *******************************************************************************/
  47. int __cdecl wcsnicmp(const wchar_t * first, const wchar_t * last, size_t count)
  48. {
  49. if (!count)
  50. return 0;
  51. while (--count && *first && wcUp(*first) == wcUp(*last))
  52. {
  53. first++;
  54. last++;
  55. }
  56. return wcUp(*first) - wcUp(*last);
  57. }