MCPcopy Create free account
hub / github.com/chen3feng/toft / ShellEscape

Function ShellEscape

encoding/shell.cpp:75–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73}
74
75std::string ShellEscape(const std::string& str)
76{
77 std::string result;
78 for (size_t i = 0; i < str.size(); ++i) {
79 switch (str[i]) {
80 case '\a':
81 result += "\\a";
82 break;
83 case '\b':
84 result += "\\b";
85 break;
86 case '\f':
87 result += "\\f";
88 break;
89 case '\n':
90 result += "\\n";
91 break;
92 case '\r':
93 result += "\\r";
94 break;
95 case '\t':
96 result += "\\t";
97 break;
98 case '\v':
99 result += "\\v";
100 break;
101 case ' ':
102 case '!':
103 case '"':
104 case '#':
105 case '$':
106 case '&':
107 case '(':
108 case ')':
109 case '*':
110 case ',':
111 case ':':
112 case ';':
113 case '?':
114 case '@':
115 case '[':
116 case '\\':
117 case ']':
118 case '`':
119 case '{':
120 case '}':
121 result += '\\';
122 // fall through
123 default:
124 result += str[i];
125 break;
126 }
127 }
128 return result;
129}
130
131static int DecodeHex(char c)
132{

Callers 1

TESTFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by 1

TESTFunction · 0.68