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

  1. /***
  2. *mbsncol.c - Collate n characters of two MBCS strings
  3. *
  4. *       Copyright (c) 1994-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Collate n characters of two MBCS strings
  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. * _mbsncoll(s1, s2, n) - Collate n characters of two MBCS strings
  27. *
  28. *Purpose:
  29. *       Collates up to n charcters of two strings for lexical order.
  30. *       Strings are collated on a character basis, not a byte basis.
  31. *
  32. *Entry:
  33. *       unsigned char *s1, *s2 = strings to collate
  34. *       size_t n = maximum number of characters to collate
  35. *
  36. *Exit:
  37. *       returns <0 if s1 < s2
  38. *       returns  0 if s1 == s2
  39. *       returns >0 if s1 > s2
  40. *
  41. *Exceptions:
  42. *
  43. *******************************************************************************/
  44.  
  45. int __cdecl _mbsncoll(
  46.     const unsigned char *s1,
  47.     const unsigned char *s2,
  48.     size_t n
  49.     )
  50. {
  51. #if !defined (_WIN32)
  52.         return _mbsncmp(s1, s2, n);
  53. #else  /* !defined (_WIN32) */
  54.         int ret;
  55.         size_t bcnt1, bcnt2;
  56.  
  57.         if (n == 0)
  58.             return 0;
  59.  
  60.         bcnt1 = _mbsnbcnt(s1, n);
  61.         bcnt2 = _mbsnbcnt(s2, n);
  62.  
  63.         if (0 == (ret = __crtCompareStringA(__mblcid, 0,
  64.                 s1, bcnt1, s2, bcnt2, __mbcodepage)))
  65.             return _NLSCMPERROR;
  66.  
  67.         return ret - 2;
  68.  
  69. #endif  /* !defined (_WIN32) */
  70. }
  71.  
  72. #endif  /* _MBCS */
  73.