ReactOS 0.4.16-dev-853-g88d9285
wcscoll.cpp
Go to the documentation of this file.
1/***
2*wcscoll.c - Collate wide-character locale strings
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*
9*******************************************************************************/
10#include <corecrt_internal.h>
11#include <ctype.h>
12#include <locale.h>
13#include <string.h>
14
15
16/***
17*int wcscoll() - Collate wide-character locale strings
18*
19*Purpose:
20* Compare two wchar_t strings using the locale LC_COLLATE information.
21* In the C locale, wcscmp() is used to make the comparison.
22*
23*Entry:
24* const wchar_t *s1 = pointer to the first string
25* const wchar_t *s2 = pointer to the second string
26*
27*Exit:
28* -1 = first string less than second string
29* 0 = strings are equal
30* 1 = first string greater than second string
31* Returns _NLSCMPERROR is something went wrong
32* This range of return values may differ from other *cmp/*coll functions.
33*
34*Exceptions:
35* Input parameters are validated. Refer to the validation section of the function.
36*
37*******************************************************************************/
38
39extern "C" int __cdecl _wcscoll_l (
40 const wchar_t *_string1,
41 const wchar_t *_string2,
43 )
44{
45 int ret;
46 _LocaleUpdate _loc_update(plocinfo);
47
48 /* validation section */
49 _VALIDATE_RETURN(_string1 != nullptr, EINVAL, _NLSCMPERROR);
50 _VALIDATE_RETURN(_string2 != nullptr, EINVAL, _NLSCMPERROR);
51
52 if ( _loc_update.GetLocaleT()->locinfo->locale_name[LC_COLLATE] == nullptr )
53 return (wcscmp(_string1, _string2));
54
55 if ( 0 == (ret = __acrt_CompareStringW(
56 _loc_update.GetLocaleT()->locinfo->locale_name[LC_COLLATE],
58 _string1,
59 -1,
60 _string2,
61 -1)) )
62 {
63 errno = EINVAL;
64 return _NLSCMPERROR;
65 }
66
67 return (ret - 2);
68
69}
70
71extern "C" int __cdecl wcscoll (
72 const wchar_t *_string1,
73 const wchar_t *_string2
74 )
75{
76 if (!__acrt_locale_changed())
77 {
78 /* validation section */
79 _VALIDATE_RETURN(_string1 != nullptr, EINVAL, _NLSCMPERROR);
80 _VALIDATE_RETURN(_string2 != nullptr, EINVAL, _NLSCMPERROR);
81
82 return (wcscmp(_string1, _string2));
83 }
84 else
85 {
86 return _wcscoll_l(_string1, _string2, nullptr);
87 }
88}
#define EINVAL
Definition: acclib.h:90
#define __cdecl
Definition: accygwin.h:79
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
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define _NLSCMPERROR
Definition: string.h:19
int __cdecl _wcscoll_l(const wchar_t *_string1, const wchar_t *_string2, _locale_t plocinfo)
Definition: wcscoll.cpp:39
int __cdecl wcscoll(const wchar_t *_string1, const wchar_t *_string2)
Definition: wcscoll.cpp:71
int ret
#define SORT_STRINGSORT
Definition: winnls.h:185