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

  1. /***
  2. *mbsnicol.c - Collate n characters of strings, ignoring case (MBCS)
  3. *
  4. *       Copyright (c) 1994-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Collate n characters of strings, ignoring case (MBCS)
  8. *
  9. *******************************************************************************/
  10.  
  11. #ifdef _MBCS
  12.  
  13. #if defined (_WIN32)
  14. #include <awint.h>
  15. #include <mtdll.h>
  16. #endif  /* defined (_WIN32) */
  17.  
  18. #include <cruntime.h>
  19. #include <internal.h>
  20. #include <mbdata.h>
  21. #include <mbctype.h>
  22. #include <string.h>
  23. #include <mbstring.h>
  24.  
  25.  
  26. /***
  27. * _mbsnicoll - Collate n characters of strings, ignoring case (MBCS)
  28. *
  29. *Purpose:
  30. *       Collates up to n charcters of two strings for lexical order.
  31. *       Strings are collated on a character basis, not a byte basis.
  32. *       Case of characters is not considered.
  33. *
  34. *Entry:
  35. *       unsigned char *s1, *s2 = strings to collate
  36. *       size_t n = maximum number of characters to collate
  37. *
  38. *Exit:
  39. *       returns <0 if s1 < s2
  40. *       returns  0 if s1 == s2
  41. *       returns >0 if s1 > s2
  42. *
  43. *Exceptions:
  44. *
  45. *******************************************************************************/
  46.  
  47. int __cdecl _mbsnicoll(
  48.     const unsigned char *s1,
  49.     const unsigned char *s2,
  50.     size_t n
  51.     )
  52. {
  53. #if !defined (_WIN32)
  54.         return _mbsnicmp(s1, s2, n);
  55. #else  /* !defined (_WIN32) */
  56.         int ret;
  57.         size_t bcnt1, bcnt2;
  58.  
  59.         if (n == 0)
  60.             return 0;
  61.  
  62.         bcnt1 = _mbsnbcnt(s1, n);
  63.         bcnt2 = _mbsnbcnt(s2, n);
  64.  
  65.         if (0 == (ret = __crtCompareStringA(__mblcid, NORM_IGNORECASE,
  66.                 s1, bcnt1, s2, bcnt2, __mbcodepage)))
  67.             return _NLSCMPERROR;
  68.  
  69.         return ret - 2;
  70.  
  71. #endif  /* !defined (_WIN32) */
  72. }
  73.  
  74. #endif  /* _MBCS */
  75.