-
Notifications
You must be signed in to change notification settings - Fork 3
/
evensgn_string.hpp
46 lines (42 loc) · 1.15 KB
/
evensgn_string.hpp
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
#ifndef EVENSGN_STRING_HPP
#define EVENSGN_STRING_HPP
#include <sstream>
#include <string>
int StringToInteger(const std::string &str) {
int ret;
if (str == "") ret = 0;
else {
std::stringstream ss(str);
ss >> ret;
}
return ret;
}
std::string DecodeEscapedString(const std::string &str) {
std::string ret = "";
int pos = 0;
char c;
while (pos < (int)str.length()) {
c = str[pos++];
if (c == '\\' && pos != (int)str.length()) {
switch (str[pos]) {
case 'a': c = '\a'; break;
case 'b': c = '\b'; break;
case 'f': c = '\f'; break;
case 'n': c = '\n'; break;
case 'r': c = '\r'; break;
case 't': c = '\t'; break;
case 'v': c = '\v'; break;
case '\\': c = '\\'; break;
case '?': c = '\?'; break;
case '\'': c = '\''; break;
case '\"': c = '\"'; break;
case '0': c = '\0'; break;
default: continue; // invalid escaped sequence
}
++pos;
}
ret += c;
}
return ret;
}
#endif // EVENSGN_STRING_HPP