-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCaseInsensitiveUtils.hpp
More file actions
41 lines (34 loc) · 1016 Bytes
/
CaseInsensitiveUtils.hpp
File metadata and controls
41 lines (34 loc) · 1016 Bytes
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
#pragma once
#include <boost/algorithm/string/predicate.hpp>
#include <boost/functional/hash.hpp>
// Based on an example from Boost Functional
struct CaseInsensitiveComparator
{
CaseInsensitiveComparator() {}
explicit CaseInsensitiveComparator(std::locale const& l) : locale_(l) {}
template <typename String1, typename String2>
bool operator()(String1 const& x1, String2 const& x2) const
{
return boost::algorithm::iequals(x1, x2, locale_);
}
private:
std::locale locale_;
};
struct CaseInsensitiveHasher
{
CaseInsensitiveHasher() {}
explicit CaseInsensitiveHasher(std::locale const& l) : locale_(l) {}
template <typename String>
std::size_t operator()(String const& x) const
{
std::size_t seed = 0;
for (typename String::const_iterator it = x.begin();
it != x.end(); ++it)
{
boost::hash_combine(seed, std::toupper(*it, locale_));
}
return seed;
}
private:
std::locale locale_;
};