-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInsensitiveMap.h
58 lines (51 loc) · 1.4 KB
/
InsensitiveMap.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* @file InsensitiveMap.h
* @brief Definition of InsensitiveMap.
*
* Copyright (c) 2020-forever Vlad Rogozin ([email protected])
*
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
* or copy at http://opensource.org/licenses/MIT)
*/
#ifndef RED_INSENSITIVEMAP_H
#define RED_INSENSITIVEMAP_H
#include <strings.h>
#include <string>
#include <map>
#define REDINSENSITIVEMAP_VERSION "1.0"
namespace Red {
//
// Private.
//
namespace _InsensitiveMap {
/**
* @brief CaseInsensitiveComparator
*
* Definition of struct which redefines ".at(...)" function into insensitive.
*/
struct CaseInsensitiveComparator {
/**
* @brief operator ()
*
* @param a First variable.
* @param b Second Variable.
*
* @return True if First variable equals to second one.
*/
bool operator()(const std::string& a, const std::string& b) const noexcept {
return ::strcasecmp(a.c_str(), b.c_str()) < 0;
}
};
}
//
// Public.
//
/**
* @brief InsensitiveMap
*
* Definition of InsensitiveMap.
*/
template <typename T1, typename T2>
using InsensitiveMap = std::map<T1, T2, _InsensitiveMap::CaseInsensitiveComparator>;
}
#endif // RED_INSENSITIVEMAP_H