Check the propertyset when matching the propertyid
[openal-soft.git] / common / alstring.cpp
blob945dbc3ae3c5b0afb89450e2aadb986b1a5e50ac
2 #include "config.h"
4 #include "alstring.h"
6 #include <algorithm>
7 #include <cctype>
8 #include <cwctype>
9 #include <cstring>
10 #include <string>
13 namespace al {
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());
22 while(ch1 != ch1end)
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;
27 ++ch0; ++ch1;
30 if(str0.size() < str1.size()) return -1;
31 if(str0.size() > str1.size()) return 1;
32 return 0;
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());
42 while(ch1 != ch1end)
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;
47 ++ch0; ++ch1;
50 if(str0.size() < str1.size()) return -1;
51 if(str0.size() > str1.size()) return 1;
52 return 0;
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)});
64 } // namespace al