ReactOS 0.4.16-dev-853-g88d9285
wcsnicol.cpp
Go to the documentation of this file.
1/***
2*wcsnicoll.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* Compares at most n characters of two strings.
10*
11*******************************************************************************/
12#include <corecrt_internal.h>
13#include <ctype.h>
14#include <locale.h>
15#include <string.h>
16
17/***
18*int _wcsnicoll() - Collate wide-character locale strings without regard to case
19*
20*Purpose:
21* Compare two wchar_t strings using the locale LC_COLLATE information
22* without regard to case.
23* Compares at most n characters of two strings.
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* size_t count - maximum number of characters to compare
30*
31*Exit:
32* -1 = first string less than second string
33* 0 = strings are equal
34* 1 = first string greater than second string
35* Returns _NLSCMPERROR is something went wrong
36* This range of return values may differ from other *cmp/*coll functions.
37*
38*Exceptions:
39* Input parameters are validated. Refer to the validation section of the function.
40*
41*******************************************************************************/
42
43extern "C" int __cdecl _wcsnicoll_l (
44 const wchar_t *_string1,
45 const wchar_t *_string2,
46 size_t count,
48 )
49{
50 int ret;
51
52 if (!count)
53 {
54 return 0;
55 }
56
57 /* validation section */
58 _VALIDATE_RETURN(_string1 != nullptr, EINVAL, _NLSCMPERROR);
59 _VALIDATE_RETURN(_string2 != nullptr, EINVAL, _NLSCMPERROR);
61
62 _LocaleUpdate _loc_update(plocinfo);
63
64 if ( _loc_update.GetLocaleT()->locinfo->locale_name[LC_COLLATE] == nullptr )
65 {
66 return __ascii_wcsnicmp(_string1, _string2, count);
67 }
68
69 if ( 0 == (ret = __acrt_CompareStringW(
70 _loc_update.GetLocaleT()->locinfo->locale_name[LC_COLLATE],
72 _string1,
73 (int)count,
74 _string2,
75 (int)count)) )
76 {
77 errno = EINVAL;
78 return _NLSCMPERROR;
79 }
80
81 return (ret - 2);
82}
83
84extern "C" int __cdecl _wcsnicoll (
85 const wchar_t *_string1,
86 const wchar_t *_string2,
87 size_t count
88 )
89{
90 if (!__acrt_locale_changed())
91 {
92 /* validation section */
93 _VALIDATE_RETURN(_string1 != nullptr, EINVAL, _NLSCMPERROR);
94 _VALIDATE_RETURN(_string2 != nullptr, EINVAL, _NLSCMPERROR);
96
97 return __ascii_wcsnicmp(_string1, _string2, count);
98 }
99 else
100 {
101 return _wcsnicoll_l(_string1, _string2, count, nullptr);
102 }
103}
#define EINVAL
Definition: acclib.h:90
#define __cdecl
Definition: accygwin.h:79
_Check_return_ int __cdecl __ascii_wcsnicmp(_In_reads_or_z_(count) const wchar_t *lhs, _In_reads_or_z_(count) const wchar_t *rhs, _In_ size_t count)
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)
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define LC_COLLATE
Definition: locale.h:18
#define INT_MAX
Definition: intsafe.h:150
_locale_t plocinfo
Definition: ismbbyte.cpp:75
#define errno
Definition: errno.h:18
#define _NLSCMPERROR
Definition: string.h:19
int __cdecl _wcsnicoll(const wchar_t *_string1, const wchar_t *_string2, size_t count)
Definition: wcsnicol.cpp:84
int __cdecl _wcsnicoll_l(const wchar_t *_string1, const wchar_t *_string2, size_t count, _locale_t plocinfo)
Definition: wcsnicol.cpp:43
int ret
#define NORM_IGNORECASE
Definition: winnls.h:178
#define SORT_STRINGSORT
Definition: winnls.h:185