ReactOS 0.4.16-dev-853-g88d9285
wcsicoll.cpp
Go to the documentation of this file.
1/***
2*wcsicoll.c - Collate wide-character locale strings without regard to case
3*
4* Copyright (c) Microsoft Corporation. All rights reserved.
5*
6*Purpose:
7* Compare two wchar_t strings using the locale LC_COLLATE information
8* without regard to case.
9*
10*******************************************************************************/
11#include <corecrt_internal.h>
12#include <ctype.h>
13#include <locale.h>
14#include <string.h>
15
16#pragma warning(disable:__WARNING_POTENTIAL_BUFFER_OVERFLOW_NULLTERMINATED) // 26018 Prefast can't see that we are checking for terminal nul.
17
18/***
19*int _wcsicoll() - Collate wide-character locale strings without regard to case
20*
21*Purpose:
22* Compare two wchar_t strings using the locale LC_COLLATE information
23* without regard to case.
24* In the C locale, _wcsicmp() is used to make the comparison.
25*
26*Entry:
27* const wchar_t *s1 = pointer to the first string
28* const wchar_t *s2 = pointer to the second string
29*
30*Exit:
31* -1 = first string less than second string
32* 0 = strings are equal
33* 1 = first string greater than second string
34* Returns _NLSCMPERROR is something went wrong
35* This range of return values may differ from other *cmp/*coll functions.
36*
37*Exceptions:
38* Input parameters are validated. Refer to the validation section of the function.
39*
40*******************************************************************************/
41
42extern "C" int __cdecl _wcsicoll_l (
43 const wchar_t *_string1,
44 const wchar_t *_string2,
46 )
47{
48 int ret;
49 _LocaleUpdate _loc_update(plocinfo);
50
51 /* validation section */
52 _VALIDATE_RETURN(_string1 != nullptr, EINVAL, _NLSCMPERROR );
53 _VALIDATE_RETURN(_string2 != nullptr, EINVAL, _NLSCMPERROR );
54
55 if ( _loc_update.GetLocaleT()->locinfo->locale_name[LC_COLLATE] == nullptr )
56 {
57 return __ascii_wcsicmp(_string1, _string2);
58 }
59
60 if ( 0 == (ret = __acrt_CompareStringW(
61 _loc_update.GetLocaleT()->locinfo->locale_name[LC_COLLATE],
63 _string1,
64 -1,
65 _string2,
66 -1)) )
67 {
68 errno = EINVAL;
69 return _NLSCMPERROR;
70 }
71
72 return (ret - 2);
73}
74
75extern "C" int __cdecl _wcsicoll (
76 const wchar_t *_string1,
77 const wchar_t *_string2
78 )
79{
80 if (!__acrt_locale_changed())
81 {
82 /* validation section */
83 _VALIDATE_RETURN(_string1 != nullptr, EINVAL, _NLSCMPERROR );
84 _VALIDATE_RETURN(_string2 != nullptr, EINVAL, _NLSCMPERROR );
85
86 return __ascii_wcsicmp(_string1, _string2);
87 }
88 else
89 {
90 return _wcsicoll_l(_string1, _string2, nullptr);
91 }
92
93}
#define EINVAL
Definition: acclib.h:90
#define __cdecl
Definition: accygwin.h:79
_Check_return_ int __cdecl __ascii_wcsicmp(_In_z_ const wchar_t *lhs, _In_z_ const wchar_t *rhs)
int __cdecl __acrt_CompareStringW(_In_ LPCWSTR _LocaleName, _In_ DWORD _DwCmpFlags, _In_CRT_NLS_string_(_CchCount1) PCWCH _LpString1, _In_ int _CchCount1, _In_CRT_NLS_string_(_CchCount2) PCWCH _LpString2, _In_ int _CchCount2)
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
#define LC_COLLATE
Definition: locale.h:18
_locale_t plocinfo
Definition: ismbbyte.cpp:75
#define errno
Definition: errno.h:18
#define _NLSCMPERROR
Definition: string.h:19
int __cdecl _wcsicoll_l(const wchar_t *_string1, const wchar_t *_string2, _locale_t plocinfo)
Definition: wcsicoll.cpp:42
int __cdecl _wcsicoll(const wchar_t *_string1, const wchar_t *_string2)
Definition: wcsicoll.cpp:75
int ret
#define NORM_IGNORECASE
Definition: winnls.h:178
#define SORT_STRINGSORT
Definition: winnls.h:185