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