15 int case_compare(const std::string_view str0
, const std::string_view str1
) noexcept
17 using Traits
= std::string_view::traits_type
;
19 auto ch0
= str0
.cbegin();
20 auto ch1
= str1
.cbegin();
21 auto ch1end
= ch1
+ std::min(str0
.size(), str1
.size());
24 const int u0
{std::toupper(Traits::to_int_type(*ch0
))};
25 const int u1
{std::toupper(Traits::to_int_type(*ch1
))};
26 if(const int diff
{u0
-u1
}) return diff
;
30 if(str0
.size() < str1
.size()) return -1;
31 if(str0
.size() > str1
.size()) return 1;
35 int case_compare(const std::wstring_view str0
, const std::wstring_view str1
) noexcept
37 using Traits
= std::wstring_view::traits_type
;
39 auto ch0
= str0
.cbegin();
40 auto ch1
= str1
.cbegin();
41 auto ch1end
= ch1
+ std::min(str0
.size(), str1
.size());
44 const auto u0
= std::towupper(Traits::to_int_type(*ch0
));
45 const auto u1
= std::towupper(Traits::to_int_type(*ch1
));
46 if(const auto diff
= static_cast<int>(u0
-u1
)) return diff
;
50 if(str0
.size() < str1
.size()) return -1;
51 if(str0
.size() > str1
.size()) return 1;
55 int strcasecmp(const char *str0
, const char *str1
) noexcept
56 { return case_compare(str0
, str1
); }
58 int strncasecmp(const char *str0
, const char *str1
, std::size_t len
) noexcept
60 return case_compare(std::string_view
{str0
, std::min(std::strlen(str0
), len
)},
61 std::string_view
{str1
, std::min(std::strlen(str1
), len
)});