MCPcopy Create free account
hub / github.com/HaxeFoundation/hxcpp / TQuoted

Function TQuoted

src/hx/libs/std/Process.cpp:126–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124
125template<typename T>
126static String TQuoted(const T *ptr, int len)
127{
128 std::vector<T> quoted;
129 quoted.reserve(len*2);
130
131 unsigned int bs_count = 0;
132 for(int j=0;j<len;j++)
133 {
134 T c = ptr[j];
135 switch( c )
136 {
137 case '"':
138 // Double backslashes.
139 for (int k=0;k<bs_count*2;k++)
140 quoted.push_back('\\');
141 bs_count = 0;
142 quoted.push_back('\\');
143 quoted.push_back('"');
144 break;
145 case '\\':
146 // Don't know if we need to double yet.
147 bs_count++;
148 break;
149 default:
150 // Normal char
151 for (int k=0;k<bs_count;k++)
152 quoted.push_back('\\');
153 bs_count = 0;
154 quoted.push_back(c);
155 break;
156 }
157 }
158 // Add remaining backslashes, if any.
159 for (int k=0;k<bs_count*2;k++)
160 quoted.push_back('\\');
161 int qlen = (int)quoted.size();
162 quoted.push_back('\0');
163
164 return String::create( &quoted[0], qlen );
165}
166
167static String quoteString(String v)
168{

Callers 1

quoteStringFunction · 0.85

Calls 2

reserveMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected