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

  1. /***
  2. *wcsicmp.c - contains case-insensitive wide string comp routine _wcsicmp
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       contains _wcsicmp()
  8. *
  9. *******************************************************************************/
  10.  
  11.  
  12. #include <cruntime.h>
  13. #include <setlocal.h>
  14. #include <string.h>
  15. #include <locale.h>
  16. #include <ctype.h>
  17. #include <setlocal.h>
  18. #include <mtdll.h>
  19.  
  20. /***
  21. *int _wcsicmp(dst, src) - compare wide-character strings, ignore case
  22. *
  23. *Purpose:
  24. *       _wcsicmp perform a case-insensitive wchar_t string comparision.
  25. *       _wcsicmp is independent of locale.
  26. *
  27. *Entry:
  28. *       wchar_t *dst, *src - strings to compare
  29. *
  30. *Return:
  31. *       <0 if dst < src
  32. *        0 if dst = src
  33. *       >0 if dst > src
  34. *       This range of return values may differ from other *cmp/*coll functions.
  35. *
  36. *Exceptions:
  37. *
  38. *******************************************************************************/
  39.  
  40. int __cdecl _wcsicmp (
  41.         const wchar_t * dst,
  42.         const wchar_t * src
  43.         )
  44. {
  45.         wchar_t f,l;
  46. #if defined (_MT)
  47.         int local_lock_flag;
  48. #endif  /* defined (_MT) */
  49.  
  50.         if ( __lc_handle[LC_CTYPE] == _CLOCALEHANDLE ) {
  51.             do  {
  52.                 f = ((*dst <= L'Z') && (*dst >= L'A'))
  53.                     ? *dst + L'a' - L'A'
  54.                     : *dst;
  55.                 l = ((*src <= L'Z') && (*src >= L'A'))
  56.                     ? *src + L'a' - L'A'
  57.                     : *src;
  58.                 dst++;
  59.                 src++;
  60.             } while ( (f) && (f == l) );
  61.         }
  62.         else {
  63.             _lock_locale( local_lock_flag );
  64.             do  {
  65.                 f = _towlower_lk( (unsigned short)(*(dst++)) );
  66.                 l = _towlower_lk( (unsigned short)(*(src++)) );
  67.             } while ( (f) && (f == l) );
  68.             _unlock_locale( local_lock_flag )
  69.         }
  70.  
  71.         return (int)(f - l);
  72. }
  73.  
  74.