xref: /reactos/sdk/lib/ucrt/string/stricoll.cpp (revision 04e0dc4a)
1 /***
2 *stricoll.c - Collate locale strings without regard to case
3 *
4 *       Copyright (c) Microsoft Corporation. All rights reserved.
5 *
6 *Purpose:
7 *       Compare two 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 *int _stricoll() - Collate locale strings without regard to case
17 *
18 *Purpose:
19 *       Compare two strings using the locale LC_COLLATE information
20 *       without regard to case.
21 *
22 *Entry:
23 *       const char *s1 = pointer to the first string
24 *       const char *s2 = pointer to the second string
25 *
26 *Exit:
27 *       Less than 0    = first string less than second string
28 *       0              = strings are equal
29 *       Greater than 0 = first string greater than second string
30 *       Returns _NLSCMPERROR is something went wrong
31 *
32 *Exceptions:
33 *       Input parameters are validated. Refer to the validation section of the function.
34 *
35 *******************************************************************************/
36 
_stricoll_l(const char * _string1,const char * _string2,_locale_t plocinfo)37 extern "C" int __cdecl _stricoll_l (
38         const char *_string1,
39         const char *_string2,
40         _locale_t plocinfo
41         )
42 {
43     int ret;
44     _LocaleUpdate _loc_update(plocinfo);
45 
46     /* validation section */
47     _VALIDATE_RETURN(_string1 != nullptr, EINVAL, _NLSCMPERROR);
48     _VALIDATE_RETURN(_string2 != nullptr, EINVAL, _NLSCMPERROR);
49 
50     if ( _loc_update.GetLocaleT()->locinfo->locale_name[LC_COLLATE] == nullptr )
51     {
52         return _stricmp(_string1, _string2);
53     }
54 
55     if ( 0 == (ret = __acrt_CompareStringA(_loc_update.GetLocaleT(),
56                     _loc_update.GetLocaleT()->locinfo->locale_name[LC_COLLATE],
57                     SORT_STRINGSORT | NORM_IGNORECASE,
58                     _string1,
59                     -1,
60                     _string2,
61                     -1,
62                     _loc_update.GetLocaleT()->locinfo->lc_collate_cp)) )
63     {
64         errno = EINVAL;
65         return _NLSCMPERROR;
66     }
67 
68     return (ret - 2);
69 
70 }
71 
_stricoll(const char * _string1,const char * _string2)72 extern "C" int __cdecl _stricoll (
73         const char *_string1,
74         const char *_string2
75         )
76 {
77     if (!__acrt_locale_changed())
78     {
79         return _stricmp(_string1, _string2);
80     }
81     else
82     {
83         return _stricoll_l(_string1, _string2, nullptr);
84     }
85 
86 }
87