Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
2.8 KiB

  1. /***
  2. *mbsnicol.c - Collate n characters of strings, ignoring case (MBCS)
  3. *
  4. * Copyright (c) 1994-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Collate n characters of strings, ignoring case (MBCS)
  8. *
  9. *Revision History:
  10. * 05-12-94 CFW Module created from mbs*cmp.c
  11. * 06-03-94 CFW Allow non-_INTL.
  12. * 07-26-94 CFW Fix for bug #13384.
  13. * 09-06-94 CFW Allow non-_WIN32!.
  14. * 12-21-94 CFW Remove fcntrlcomp NT 3.1 hack.
  15. * 09-26-97 BWT Fix POSIX
  16. * 04-17-98 GJF Implemented multithread support based on threadmbcinfo
  17. * structs
  18. * 12-18-98 GJF Changes for 64-bit size_t.
  19. * 05-17-99 PML Remove all Macintosh support.
  20. *
  21. *******************************************************************************/
  22. #ifdef _MBCS
  23. #include <awint.h>
  24. #include <mtdll.h>
  25. #include <cruntime.h>
  26. #include <internal.h>
  27. #include <mbdata.h>
  28. #include <mbctype.h>
  29. #include <string.h>
  30. #include <mbstring.h>
  31. /***
  32. * _mbsnicoll - Collate n characters of strings, ignoring case (MBCS)
  33. *
  34. *Purpose:
  35. * Collates up to n charcters of two strings for lexical order.
  36. * Strings are collated on a character basis, not a byte basis.
  37. * Case of characters is not considered.
  38. *
  39. *Entry:
  40. * unsigned char *s1, *s2 = strings to collate
  41. * size_t n = maximum number of characters to collate
  42. *
  43. *Exit:
  44. * returns <0 if s1 < s2
  45. * returns 0 if s1 == s2
  46. * returns >0 if s1 > s2
  47. *
  48. *Exceptions:
  49. *
  50. *******************************************************************************/
  51. int __cdecl _mbsnicoll(
  52. const unsigned char *s1,
  53. const unsigned char *s2,
  54. size_t n
  55. )
  56. {
  57. #if defined(_POSIX_)
  58. return _mbsnicmp(s1, s2, n);
  59. #else
  60. int ret;
  61. size_t bcnt1, bcnt2;
  62. #ifdef _MT
  63. pthreadmbcinfo ptmbci = _getptd()->ptmbcinfo;
  64. if ( ptmbci != __ptmbcinfo )
  65. ptmbci = __updatetmbcinfo();
  66. #endif
  67. if (n == 0)
  68. return 0;
  69. #ifdef _MT
  70. bcnt1 = __mbsnbcnt_mt(ptmbci, s1, n);
  71. bcnt2 = __mbsnbcnt_mt(ptmbci, s2, n);
  72. #else
  73. bcnt1 = _mbsnbcnt(s1, n);
  74. bcnt2 = _mbsnbcnt(s2, n);
  75. #endif
  76. #ifdef _MT
  77. if ( 0 == (ret = __crtCompareStringA( ptmbci->mblcid,
  78. #else
  79. if ( 0 == (ret = __crtCompareStringA( __mblcid,
  80. #endif
  81. NORM_IGNORECASE,
  82. s1,
  83. (int)bcnt1,
  84. s2,
  85. (int)bcnt2,
  86. #ifdef _MT
  87. ptmbci->mbcodepage )) )
  88. #else
  89. __mbcodepage )) )
  90. #endif
  91. return _NLSCMPERROR;
  92. return ret - 2;
  93. #endif /* _POSIX_ */
  94. }
  95. #endif /* _MBCS */