Reactos
at master 103 lines 3.1 kB view raw
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, 47 _locale_t plocinfo 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); 60 _VALIDATE_RETURN(count <= INT_MAX, 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], 71 SORT_STRINGSORT | NORM_IGNORECASE, 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); 95 _VALIDATE_RETURN(count <= INT_MAX, EINVAL, _NLSCMPERROR); 96 97 return __ascii_wcsnicmp(_string1, _string2, count); 98 } 99 else 100 { 101 return _wcsnicoll_l(_string1, _string2, count, nullptr); 102 } 103}