-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpch.cpp
98 lines (88 loc) · 2.63 KB
/
pch.cpp
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
89
90
91
92
93
94
95
96
97
98
// pch.cpp: source file corresponding to the pre-compiled header
#include "pch.h"
/// <summary>
/// split string
/// </summary>
/// <param name="str">The text</param>
/// <param name="delimiter">The delimiter</param>
/// <returns>Vector of split string</returns>
static std::vector<std::string> split_string(std::string& str, const std::string delimiter)
{
size_t pos_start = 0, pos_end, delim_len = delimiter.length();
std::string token;
std::vector<std::string> res;
while ((pos_end = str.find(delimiter, pos_start)) != std::string::npos) {
token = str.substr(pos_start, pos_end - pos_start);
pos_start = pos_end + delim_len;
res.push_back(token);
}
res.push_back(str.substr(pos_start));
return res;
}
/// <summary>
/// trim left front
/// </summary>
/// <param name="source">the source</param>
/// <returns>the trimmed string</returns>
static std::string left_trim(const char* source)
{
const char* trim = "";
std::string s(source);
s.erase(0, s.find_first_not_of(trim));
return std::string(s.c_str());
}
/// <summary>
/// trim right end
/// </summary>
/// <param name="source">the source</param>
/// <returns>the trimmed string</returns>
static std::string right_trim(const char* source)
{
const char* trim = "";
std::string s(source);
s.erase(s.find_last_not_of(trim) + 1);
return std::string(s.c_str());
}
/// <summary>
/// trim both front and end
/// </summary>
/// <param name="source">the source</param>
/// <returns>the trimmed string</returns>
static std::string both_trim(const char* source)
{
return left_trim(right_trim(source).c_str());
}
/// <summary>
/// trim left front
/// </summary>
/// <param name="source">the source</param>
/// <param name="trim">the trim value</param>
/// <returns>the trimmed string</returns>
static std::string left_trim(const char* source, const char* trim)
{
std::string s(source);
s.erase(0, s.find_first_not_of(trim));
return std::string(s.c_str());
}
/// <summary>
/// trim right end
/// </summary>
/// <param name="source">the source</param>
/// <param name="trim">the trim value</param>
/// <returns>the trimmed string</returns>
static std::string right_trim(const char* source, const char* trim)
{
std::string s(source);
s.erase(s.find_last_not_of(trim) + 1);
return std::string(s.c_str());
}
/// <summary>
/// trim both front and end
/// </summary>
/// <param name="source">the source</param>
/// <param name="trim">the trim value</param>
/// <returns>the trimmed string</returns>
static std::string both_trim(const char* source, const char* trim)
{
return left_trim(right_trim(source, trim).c_str(), trim);
}