blob: 4a84be1db24a1c1181df22f5971aec409dbe3a59 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#include "config.h"
#include "alstring.h"
#include <cctype>
#include <string>
namespace {
int to_upper(const char ch)
{
using char8_traits = std::char_traits<char>;
return std::toupper(char8_traits::to_int_type(ch));
}
} // namespace
namespace al {
int strcasecmp(const char *str0, const char *str1) noexcept
{
do {
const int diff{to_upper(*str0) - to_upper(*str1)};
if(diff < 0) return -1;
if(diff > 0) return 1;
} while(*(str0++) && *(str1++));
return 0;
}
int strncasecmp(const char *str0, const char *str1, std::size_t len) noexcept
{
if(len > 0)
{
do {
const int diff{to_upper(*str0) - to_upper(*str1)};
if(diff < 0) return -1;
if(diff > 0) return 1;
} while(--len && *(str0++) && *(str1++));
}
return 0;
}
} // namespace al
|