ReactOS 0.4.16-dev-822-gbcedb53
mbsnicol.cpp
Go to the documentation of this file.
1/***
2*mbsnicol.c - Collate n characters of strings, ignoring case (MBCS)
3*
4* Copyright (c) Microsoft Corporation. All rights reserved.
5*
6*Purpose:
7* Collate n characters of strings, ignoring case (MBCS)
8*
9*******************************************************************************/
10#ifndef _MBCS
11 #error This file should only be compiled with _MBCS defined
12#endif
13
15#include <limits.h>
16#include <locale.h>
17#include <string.h>
18
19
20/***
21* _mbsnicoll - Collate n characters of strings, ignoring case (MBCS)
22*
23*Purpose:
24* Collates up to n charcters of two strings for lexical order.
25* Strings are collated on a character basis, not a byte basis.
26* Case of characters is not considered.
27*
28*Entry:
29* unsigned char *s1, *s2 = strings to collate
30* size_t n = maximum number of characters to collate
31*
32*Exit:
33* Returns <0 if s1 < s2
34* Returns 0 if s1 == s2
35* Returns >0 if s1 > s2
36* Returns _NLSCMPERROR is something went wrong
37*
38*Exceptions:
39* Input parameters are validated. Refer to the validation section of the function.
40*
41*******************************************************************************/
42
43extern "C" int __cdecl _mbsnicoll_l(
44 const unsigned char *s1,
45 const unsigned char *s2,
46 size_t n,
48 )
49{
50 int ret;
51 size_t bcnt1, bcnt2;
52 _LocaleUpdate _loc_update(plocinfo);
53
54 if (n == 0)
55 return 0;
56
57 /* validation section */
61
62 if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0)
63 return _strnicoll_l((const char *)s1, (const char *)s2, n, plocinfo);
64
65 bcnt1 = _mbsnbcnt_l(s1, n, _loc_update.GetLocaleT());
66 bcnt2 = _mbsnbcnt_l(s2, n, _loc_update.GetLocaleT());
67
68 if ( 0 == (ret = __acrt_CompareStringA(
69 _loc_update.GetLocaleT(),
70 _loc_update.GetLocaleT()->mbcinfo->mblocalename,
72 (const char *)s1,
73 (int)bcnt1,
74 (char *)s2,
75 (int)bcnt2,
76 _loc_update.GetLocaleT()->mbcinfo->mbcodepage )) )
77 {
78 errno = EINVAL;
79 return _NLSCMPERROR;
80 }
81
82 return ret - 2;
83
84}
85
86extern "C" int (__cdecl _mbsnicoll)(
87 const unsigned char *s1,
88 const unsigned char *s2,
89 size_t n
90 )
91{
92 return _mbsnicoll_l(s1, s2, n, nullptr);
93}
#define EINVAL
Definition: acclib.h:90
#define __cdecl
Definition: accygwin.h:79
int __cdecl __acrt_CompareStringA(_In_opt_ _locale_t _Plocinfo, _In_ LPCWSTR _LocaleName, _In_ DWORD _DwCmpFlags, _In_CRT_NLS_string_(_CchCount1) PCCH _LpString1, _In_ int _CchCount1, _In_CRT_NLS_string_(_CchCount2) PCCH _LpString2, _In_ int _CchCount2, _In_ int _CodePage)
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
_Check_return_ _CRTIMP int __cdecl _strnicoll_l(_In_z_ const char *str1, _In_z_ const char *str2, _In_ size_t maxcount, _In_opt_ _locale_t locale)
Definition: stubs.c:564
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
GLdouble n
Definition: glext.h:7729
_Check_return_ _CRTIMP size_t __cdecl _mbsnbcnt_l(_In_reads_bytes_(_MaxCount) _Pre_z_ const unsigned char *_Str, _In_ size_t _MaxCount, _In_opt_ _locale_t _Locale)
_Check_return_ _CRTIMP int __cdecl _mbsnicoll(_In_z_ const unsigned char *_Str1, _In_z_ const unsigned char *_Str2, _In_ size_t _MaxCount)
#define INT_MAX
Definition: intsafe.h:150
_locale_t plocinfo
Definition: ismbbyte.cpp:75
int __cdecl _mbsnicoll_l(const unsigned char *s1, const unsigned char *s2, size_t n, _locale_t plocinfo)
Definition: mbsnicol.cpp:43
const unsigned char * s2
Definition: mbsnicol.cpp:88
const unsigned char size_t n
Definition: mbsnicol.cpp:91
struct S1 s1
#define errno
Definition: errno.h:18
#define _NLSCMPERROR
Definition: string.h:19
int ret
#define NORM_IGNORECASE
Definition: winnls.h:178
#define SORT_STRINGSORT
Definition: winnls.h:185