]> git.tdb.fi Git - ext/openal.git/blob - common/alstring.cpp
Import OpenAL Soft 1.23.1 sources
[ext/openal.git] / common / alstring.cpp
1
2 #include "config.h"
3
4 #include "alstring.h"
5
6 #include <cctype>
7 #include <string>
8
9
10 namespace {
11
12 int to_upper(const char ch)
13 {
14     using char8_traits = std::char_traits<char>;
15     return std::toupper(char8_traits::to_int_type(ch));
16 }
17
18 } // namespace
19
20 namespace al {
21
22 int strcasecmp(const char *str0, const char *str1) noexcept
23 {
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;
30 }
31
32 int strncasecmp(const char *str0, const char *str1, std::size_t len) noexcept
33 {
34     if(len > 0)
35     {
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++));
41     }
42     return 0;
43 }
44
45 } // namespace al