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.

77 lines
1.9 KiB

  1. /***
  2. *wcsicmp.c - compares two wide character strings with case insensitivity
  3. *
  4. * Copyright (c) 1985-1988, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines wcsicmp() - compares two wide character strings for lexical
  8. * order with case insensitivity.
  9. *
  10. *Revision History:
  11. * 11-Mar-92 CarlH Created.
  12. *
  13. *******************************************************************************/
  14. #include <stdlib.h>
  15. /***
  16. *wchar_t wcUp(wc) - upper case wide character
  17. *
  18. *Notes:
  19. * This was copied from AlexT's version of wcsnicmp.c from the Win4
  20. * common project.
  21. */
  22. static wchar_t wcUp(wchar_t wc)
  23. {
  24. if ('a' <= wc && wc <= 'z')
  25. wc += (wchar_t)('A' - 'a');
  26. return(wc);
  27. }
  28. /***
  29. *wcsicmp - compare two wide character strings with case insensitivity,
  30. * returning less than, equal to, or greater than
  31. *
  32. *Purpose:
  33. * WCSICMP compares two wide character strings with case insensitivity
  34. * and returns an integer to indicate whether the first is less than
  35. * the second, the two are equal, or whether the first is greater than
  36. * the second.
  37. *
  38. * Comparison is done byte by byte on an UNSIGNED basis with lower to
  39. * upper case mapping by wcUp. Null (0) is less than any other
  40. * character (1-0xffff).
  41. *
  42. *Entry:
  43. * const wchar_t * src - string for left-hand side of comparison
  44. * const wchar_t * dst - string for right-hand side of comparison
  45. *
  46. *Exit:
  47. * returns -1 if src < dst
  48. * returns 0 if src == dst
  49. * returns +1 if src > dst
  50. *
  51. *Exceptions:
  52. *
  53. *******************************************************************************/
  54. int __cdecl wcsicmp(const wchar_t * src, const wchar_t * dst)
  55. {
  56. int ret = 0 ;
  57. while( ! (ret = wcUp(*src) - wcUp(*dst)) && *dst)
  58. ++src, ++dst;
  59. if ( ret < 0 )
  60. ret = -1 ;
  61. else if ( ret > 0 )
  62. ret = 1 ;
  63. return ret;
  64. }