-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcaseinsensitivecomparer.h
43 lines (34 loc) · 1.28 KB
/
caseinsensitivecomparer.h
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
#ifndef TAG_PARSER_CASEINSENSITIVECOMPARER
#define TAG_PARSER_CASEINSENSITIVECOMPARER
#include "./global.h"
#include <string>
#include <iostream>
namespace TagParser {
/*!
* \brief The CaseInsensitiveCharComparer struct defines a method for case-insensivive character comparison (less).
*/
struct TAG_PARSER_EXPORT CaseInsensitiveCharComparer {
static constexpr unsigned char toLower(const unsigned char c)
{
return (c >= 'A' && c <= 'Z') ? (c + ('a' - 'A')) : c;
}
bool operator()(const unsigned char lhs, const unsigned char rhs) const
{
return toLower(lhs) < toLower(rhs);
}
};
/*!
* \brief The CaseInsensitiveStringComparer struct defines a method for case-insensivive string comparison (less).
*/
struct TAG_PARSER_EXPORT CaseInsensitiveStringComparer {
bool operator()(const std::string &lhs, const std::string &rhs) const
{
return std::lexicographical_compare(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(), CaseInsensitiveCharComparer());
}
bool operator()(std::string_view lhs, std::string_view rhs) const
{
return std::lexicographical_compare(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(), CaseInsensitiveCharComparer());
}
};
} // namespace TagParser
#endif // TAG_PARSER_CASEINSENSITIVECOMPARER