MCPcopy Create free account
hub / github.com/apple/foundationdb / parseLine

Function parseLine

fdbcli/fdbcli.actor.cpp:352–446  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

350}
351
352static std::vector<std::vector<StringRef>> parseLine(std::string& line, bool& err, bool& partial) {
353 err = false;
354 partial = false;
355
356 bool quoted = false;
357 std::vector<StringRef> buf;
358 std::vector<std::vector<StringRef>> ret;
359
360 size_t i = line.find_first_not_of(' ');
361 size_t offset = i;
362
363 bool forcetoken = false;
364
365 while (i <= line.length()) {
366 switch (line[i]) {
367 case ';':
368 if (!quoted) {
369 if (i > offset || (forcetoken && i == offset))
370 buf.push_back(StringRef((uint8_t*)(line.data() + offset), i - offset));
371 ret.push_back(std::move(buf));
372 offset = i = line.find_first_not_of(' ', i + 1);
373 forcetoken = false;
374 } else
375 i++;
376 break;
377 case '"':
378 quoted = !quoted;
379 line.erase(i, 1);
380 forcetoken = true;
381 break;
382 case ' ':
383 case '\n':
384 case '\t':
385 case '\r':
386 if (!quoted) {
387 if (i > offset || (forcetoken && i == offset))
388 buf.push_back(StringRef((uint8_t*)(line.data() + offset), i - offset));
389 offset = i = line.find_first_not_of(" \n\t\r", i);
390 forcetoken = false;
391 } else
392 i++;
393 break;
394 case '\\':
395 if (i + 2 > line.length()) {
396 err = true;
397 ret.push_back(std::move(buf));
398 return ret;
399 }
400 switch (line[i + 1]) {
401 char ent, save;
402 case '"':
403 case '\\':
404 case ' ':
405 case ';':
406 line.erase(i, 1);
407 break;
408 case 'x':
409 if (i + 4 > line.length()) {

Callers 3

fdbcliCompCmdFunction · 0.70
fdbcli.actor.cppFile · 0.70
Future<int> runCliFunction · 0.70

Calls 7

moveFunction · 0.85
StringRefClass · 0.50
lengthMethod · 0.45
push_backMethod · 0.45
dataMethod · 0.45
eraseMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected