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

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