forked from array2d/deepx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.cpp
More file actions
56 lines (52 loc) · 1.28 KB
/
string.cpp
File metadata and controls
56 lines (52 loc) · 1.28 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
#include "string.hpp"
namespace stdutil
{
void trimspace(string &str)
{
str.erase(0, str.find_first_not_of(" "));
str.erase(str.find_last_not_of(" ") + 1);
}
void trim(string &str, const string &chars)
{
str.erase(0, str.find_first_not_of(chars));
str.erase(str.find_last_not_of(chars) + 1);
}
string escape_markdown(const string &str)
{
std::string result;
for (char c : str)
{
switch (c)
{
case '\\':
result += "\\\\";
break;
case '\"':
result += "\\\"";
break;
case '\'':
result += "\\\'";
break;
case '\n':
result += "\\n";
break;
case '\t':
result += "\\t";
break;
case '\r':
result += "\\r";
break;
case '\b':
result += "\\b";
break;
case '\f':
result += "\\f";
break;
default:
// 普通字符直接添加
result += c;
}
}
return result;
}
} // namespace stdutil