home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / wcsicoll.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  3KB  |  89 lines

  1. /***
  2. *wcsicoll.c - Collate wide-character locale strings without regard to case
  3. *
  4. *       Copyright (c) 1988-1998, 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. *******************************************************************************/
  11.  
  12.  
  13. #include <cruntime.h>
  14. #include <windows.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <locale.h>
  18. #include <setlocal.h>
  19. #include <mtdll.h>
  20. #include <errno.h>
  21. #include <awint.h>
  22.  
  23. /***
  24. *int _wcsicoll() - Collate wide-character locale strings without regard to case
  25. *
  26. *Purpose:
  27. *       Compare two wchar_t strings using the locale LC_COLLATE information
  28. *       without regard to case.
  29. *       In the C locale, _wcsicmp() is used to make the comparison.
  30. *
  31. *Entry:
  32. *       const wchar_t *s1 = pointer to the first string
  33. *       const wchar_t *s2 = pointer to the second string
  34. *
  35. *Exit:
  36. *       -1 = first string less than second string
  37. *        0 = strings are equal
  38. *        1 = first string greater than second string
  39. *       This range of return values may differ from other *cmp/*coll functions.
  40. *
  41. *Exceptions:
  42. *       _NLSCMPERROR    = error
  43. *       errno = EINVAL
  44. *
  45. *******************************************************************************/
  46.  
  47. int __cdecl _wcsicoll (
  48.         const wchar_t *_string1,
  49.         const wchar_t *_string2
  50.         )
  51. {
  52.  
  53.         int ret;
  54. #if defined (_MT)
  55.         int local_lock_flag;
  56. #endif  /* defined (_MT) */
  57.  
  58.         if (__lc_handle[LC_COLLATE] == _CLOCALEHANDLE) {
  59.                 return (_wcsicmp(_string1, _string2));
  60.         }
  61.  
  62.         _lock_locale( local_lock_flag )
  63.  
  64. #if defined (_MT)
  65.         if (__lc_handle[LC_COLLATE] == _CLOCALEHANDLE) {
  66.                 _unlock_locale( local_lock_flag )
  67.                 return (_wcsicmp(_string1, _string2));
  68.         }
  69. #endif  /* defined (_MT) */
  70.  
  71.         if ( 0 == (ret = __crtCompareStringW( __lc_handle[LC_COLLATE],
  72.                                               SORT_STRINGSORT | NORM_IGNORECASE,
  73.                                               _string1,
  74.                                               -1,
  75.                                               _string2,
  76.                                               -1,
  77.                                               __lc_codepage )) )
  78.         {
  79.                 _unlock_locale( local_lock_flag )
  80.                 errno = EINVAL;
  81.                 return _NLSCMPERROR;
  82.         }
  83.  
  84.         _unlock_locale( local_lock_flag )
  85.         return (ret - 2);
  86.  
  87. }
  88.  
  89.