Reactos
at master 93 lines 2.8 kB view raw
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, 45 _locale_t plocinfo 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], 62 SORT_STRINGSORT | NORM_IGNORECASE, 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}