| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #include <corecrt_internal.h>
|
| #include <ctype.h>
|
| #include <locale.h>
|
| #include <string.h>
|
| #define BOUNDED_CMP
|
| #include "strcompare.h"
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| extern "C" DECLSPEC_NOINLINE int __cdecl _strnicmp_l (
|
| char const * const lhs,
|
| char const * const rhs,
|
| size_t const count,
|
| _locale_t const plocinfo
|
| )
|
| {
|
|
|
| _VALIDATE_RETURN(lhs != nullptr, EINVAL, _NLSCMPERROR);
|
| _VALIDATE_RETURN(rhs != nullptr, EINVAL, _NLSCMPERROR);
|
| _VALIDATE_RETURN(count <= INT_MAX, EINVAL, _NLSCMPERROR);
|
|
|
| if (count == 0)
|
| {
|
| return 0;
|
| }
|
|
|
| unsigned char const * lhs_ptr = reinterpret_cast<unsigned char const *>(lhs);
|
| unsigned char const * rhs_ptr = reinterpret_cast<unsigned char const *>(rhs);
|
|
|
| _LocaleUpdate _loc_update(plocinfo);
|
|
|
| int result;
|
| int lhs_value;
|
| int rhs_value;
|
| size_t remaining = count;
|
| do
|
| {
|
| lhs_value = _tolower_fast_internal(*lhs_ptr++, _loc_update.GetLocaleT());
|
| rhs_value = _tolower_fast_internal(*rhs_ptr++, _loc_update.GetLocaleT());
|
| result = lhs_value - rhs_value;
|
| }
|
| while (result == 0 && lhs_value != 0 && --remaining != 0);
|
|
|
| return result;
|
| }
|
|
|
| #if !defined(_M_IX86) || defined(_M_HYBRID_X86_ARM64)
|
|
|
| extern "C" int __cdecl __ascii_strnicmp (
|
| char const * const lhs,
|
| char const * const rhs,
|
| size_t const count
|
| )
|
| {
|
| #if defined(_M_ARM64) || defined(_M_ARM64EC) || defined(_M_HYBRID_X86_ARM64)
|
| return __ascii_stricmp_neon(lhs, rhs, count);
|
| #else
|
| if (count == 0)
|
| {
|
| return 0;
|
| }
|
|
|
| unsigned char const * lhs_ptr = reinterpret_cast<unsigned char const *>(lhs);
|
| unsigned char const * rhs_ptr = reinterpret_cast<unsigned char const *>(rhs);
|
|
|
| int result;
|
| int lhs_value;
|
| int rhs_value;
|
| size_t remaining = count;
|
| do
|
| {
|
| lhs_value = *lhs_ptr++;
|
| rhs_value = *rhs_ptr++;
|
| if (lhs_value != rhs_value)
|
| {
|
| lhs_value = __ascii_tolower(lhs_value);
|
| rhs_value = __ascii_tolower(rhs_value);
|
| }
|
| result = lhs_value - rhs_value;
|
| }
|
| while (result == 0 && lhs_value != 0 && --remaining != 0);
|
|
|
| return result;
|
| #endif
|
| }
|
|
|
| #endif
|
|
|
|
|
|
|
|
|
|
|
| static DECLSPEC_NOINLINE int _strnicmp_validate_param (
|
| char const * const lhs,
|
| char const * const rhs,
|
| size_t const count
|
| )
|
| {
|
|
|
| _VALIDATE_RETURN(lhs != nullptr, EINVAL, _NLSCMPERROR);
|
| _VALIDATE_RETURN(rhs != nullptr, EINVAL, _NLSCMPERROR);
|
| _VALIDATE_RETURN(count <= INT_MAX, EINVAL, _NLSCMPERROR);
|
| return _NLSCMPERROR;
|
| }
|
|
|
| extern "C" int __cdecl _strnicmp (
|
| char const * const lhs,
|
| char const * const rhs,
|
| size_t const count
|
| )
|
| {
|
| if (!__acrt_locale_changed())
|
| {
|
| if (lhs == nullptr || rhs == nullptr || count > INT_MAX)
|
| {
|
| return _strnicmp_validate_param(lhs, rhs, count);
|
| }
|
|
|
| return __ascii_strnicmp(lhs, rhs, count);
|
| }
|
|
|
| return _strnicmp_l(lhs, rhs, count, nullptr);
|
| }
|
|
|