Make a couple more operator bools explicit
[openal-soft.git] / common / alstring.cpp
blob4a84be1db24a1c1181df22f5971aec409dbe3a59
2 #include "config.h"
4 #include "alstring.h"
6 #include <cctype>
7 #include <string>
10 namespace {
12 int to_upper(const char ch)
14 using char8_traits = std::char_traits<char>;
15 return std::toupper(char8_traits::to_int_type(ch));
18 } // namespace
20 namespace al {
22 int strcasecmp(const char *str0, const char *str1) noexcept
24 do {
25 const int diff{to_upper(*str0) - to_upper(*str1)};
26 if(diff < 0) return -1;
27 if(diff > 0) return 1;
28 } while(*(str0++) && *(str1++));
29 return 0;
32 int strncasecmp(const char *str0, const char *str1, std::size_t len) noexcept
34 if(len > 0)
36 do {
37 const int diff{to_upper(*str0) - to_upper(*str1)};
38 if(diff < 0) return -1;
39 if(diff > 0) return 1;
40 } while(--len && *(str0++) && *(str1++));
42 return 0;
45 } // namespace al