forked from awwit/httpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.h
More file actions
74 lines (51 loc) · 2.03 KB
/
Utils.h
File metadata and controls
74 lines (51 loc) · 2.03 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
#pragma once
#include "RawData.h"
#include "FileIncoming.h"
#include <locale>
#include <vector>
#include <unordered_map>
namespace Utils
{
void toLower(std::string &str, const std::locale &loc);
void trim(std::string &str);
std::vector<std::string> explode(const std::string &str, const char sep);
std::string encodeHtmlSymbols(const std::string &str);
std::string binToHexString(const void *bin, const size_t size);
std::string hexStringToBin(const std::string &hexStr);
unsigned long long htonll(const unsigned long long src);
std::string getUniqueName();
char *stlStringToPChar(const std::string &str);
template<typename T>
void stlToRawPairs(Utils::raw_pair *raw[], const T &stl)
{
if (raw && stl.size() )
{
raw_pair *arr = new raw_pair[stl.size()];
*raw = arr;
size_t i = 0;
for (auto it = stl.cbegin(); stl.cend() != it; ++it, ++i)
{
arr[i].key = stlStringToPChar(it->first);
arr[i].value = stlStringToPChar(it->second);
}
}
}
template<typename T>
void rawPairsToStl(T &stl, const Utils::raw_pair raw[], const size_t count)
{
for (size_t i = 0; i < count; ++i)
{
stl.emplace(raw[i].key ? raw[i].key : "", raw[i].value ? raw[i].value : "");
}
}
void filesIncomingToRawFilesInfo(Utils::raw_fileinfo *raw[], const std::unordered_multimap<std::string, HttpServer::FileIncoming> &map);
void rawFilesInfoToFilesIncoming(std::unordered_multimap<std::string, HttpServer::FileIncoming> &map, const Utils::raw_fileinfo raw[], const size_t count);
void destroyRawPairs(Utils::raw_pair raw[], const size_t count);
void destroyRawFilesInfo(Utils::raw_fileinfo raw[], const size_t count);
time_t stringTimeToTimestamp(const std::string &strTime);
std::string getDatetimeAsString(const ::time_t tTime = ~0, const bool isGmtTime = false);
size_t getNumberLength(const size_t number);
bool parseCookies(const std::string &cookieHeader, std::unordered_multimap<std::string, std::string> &cookies);
std::string urlEncode(const std::string &str);
std::string urlDecode(const std::string &str);
};