dmpserverutils.h
2.8 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**************************************************************************
* file: dmpserverutils.h
* Author: wanzhongping
* Date: 2021-03-17 16:05:31
* Email: zhongpingw@chinadci.com
* copyright: 广州城市信息研究所有限公司
***************************************************************************/
#ifndef __dmpserverutils_h__
#define __dmpserverutils_h__
#include "dmap_server.h"
#include <boost/filesystem.hpp>
#include <unordered_map>
class SERVER_EXPORT DmpServerUtils
{
public:
//获取目录下的所有dll或so库文件
static int GetLibraryPaths(const boost::filesystem::path &dir, std::vector<boost::filesystem::path> &locations);
};
class CaseInsensitiveEqual {
public:
bool operator()(const std::string &str1, const std::string &str2) const noexcept {
return str1.size() == str2.size() &&
std::equal(str1.begin(), str1.end(), str2.begin(), [](char a, char b) {
return tolower(a) == tolower(b);
});
}
};
class CaseInsensitiveHash {
public:
std::size_t operator()(const std::string &str) const noexcept {
std::size_t h = 0;
std::hash<int> hash;
for(auto c : str)
h ^= hash(tolower(c)) + 0x9e3779b9 + (h << 6) + (h >> 2);
return h;
}
};
using CaseInsensitiveMultimap = std::unordered_multimap<std::string, std::string, CaseInsensitiveHash, CaseInsensitiveEqual>;
// Percent encoding and decoding
class Percent {
public:
static std::string encode(const std::string &value) noexcept;
static std::string decode(const std::string &value) noexcept;
};
//自定义大小写不敏感的map
struct ci_less : std::binary_function<std::string, std::string, bool>
{
// case-independent (ci) compare_less binary function
struct nocase_compare : public std::binary_function<unsigned char, unsigned char, bool>
{
bool operator()(const unsigned char &c1, const unsigned char &c2) const
{
return tolower(c1) < tolower(c2);
}
};
bool operator()(const std::string &s1, const std::string &s2) const
{
return std::lexicographical_compare(s1.begin(), s1.end(), // source range
s2.begin(), s2.end(), // dest range
nocase_compare()); // comparison
}
};
using CIMap = std::map<std::string, std::string, ci_less>;
// Query string creation and parsing
class QueryString {
public:
// Returns query string created from given field names and values
static std::string create(const CIMap &fields) noexcept;
// Returns query keys with percent-decoded values.
static CIMap parse(const std::string &query_string) noexcept;
};
#endif //__dmpserverutils_h__