MCPcopy Create free account
hub / github.com/DFHack/dfhack / cheap_tokenise

Method cheap_tokenise

library/Core.cpp:235–292  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

233thread_local int CommandDepthCounter::depth = 0;
234
235void Core::cheap_tokenise(std::string const& input, std::vector<std::string>& output)
236{
237 std::string *cur = nullptr;
238 size_t i = 0;
239
240 // Check the first non-space character
241 while (i < input.size() && isspace(input[i])) i++;
242
243 // Special verbatim argument mode?
244 if (i < input.size() && input[i] == ':')
245 {
246 // Read the command
247 std::string cmd;
248 i++;
249 while (i < input.size() && !isspace(input[i]))
250 cmd.push_back(input[i++]);
251 if (!cmd.empty())
252 output.push_back(cmd);
253
254 // Find the argument
255 while (i < input.size() && isspace(input[i])) i++;
256
257 if (i < input.size())
258 output.push_back(input.substr(i));
259
260 return;
261 }
262
263 // Otherwise, parse in the regular quoted mode
264 for (; i < input.size(); i++)
265 {
266 unsigned char c = input[i];
267 if (isspace(c)) {
268 cur = nullptr;
269 } else {
270 if (!cur) {
271 output.push_back("");
272 cur = &output.back();
273 }
274
275 if (c == '"') {
276 for (i++; i < input.size(); i++) {
277 c = input[i];
278 if (c == '"')
279 break;
280 else if (c == '\\') {
281 if (++i < input.size())
282 cur->push_back(input[i]);
283 }
284 else
285 cur->push_back(c);
286 }
287 } else {
288 cur->push_back(c);
289 }
290 }
291 }
292}

Callers

nothing calls this directly

Calls 2

sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected