| src/CfgParser.cc | |
| 465 | @@ -465,64 +465,41 @@ |
| 465 | } |
| 466 | |
| 467 | //! @brief Parses from = to end of " pair. |
| 468 | bool |
| 469 | void |
| 470 | CfgParser::parse_value(CfgParserSource *source, std::string &value) |
| 471 | { |
| 472 | // Init parse buffer and reserve memory. |
| 473 | string buf; |
| 474 | buf.reserve(PARSE_BUF_SIZE); |
| 475 | |
| 476 | // We expect to get a " after the =, however to do proper error reporting |
| 477 | // we store the what we get between so we can show the output if it includes |
| 478 | // anything else than spaces. |
| 479 | int c, next; |
| 480 | bool garbage = false; |
| 481 | while ((c = source->getc()) != EOF) { |
| 482 | if (c == '"') { |
| 483 | break; |
| 484 | } |
| 485 | |
| 486 | buf += c; |
| 487 | |
| 488 | if (! isspace(c)) { |
| 489 | garbage = true; |
| 490 | } |
| 491 | } |
| 492 | // We expect to get a " after the =, however we ignore anything else. |
| 493 | int c; |
| 494 | while ((c = source->getc()) != EOF && c != '"') |
| 495 | ; |
| 496 | |
| 497 | // Check if we got to a " or found EOF first. |
| 498 | if (c == EOF) { |
| 499 | cerr << "Reached EOF before opening \" in value." << endl; |
| 500 | return false; |
| 501 | } |
| 502 | |
| 503 | // Check if there was garbage between = and ". |
| 504 | if (garbage) { |
| 505 | // pass, do nothing |
| 506 | return; |
| 507 | } |
| 508 | |
| 509 | // Parse until next ", and escape characters after \. |
| 510 | buf.clear(); |
| 511 | while ((c = source->getc()) != EOF) { |
| 512 | while ((c = source->getc()) != EOF && c != '"') { |
| 513 | // Escape character after \, if newline drop it. |
| 514 | if (c == '\\') { |
| 515 | next = source->getc(); |
| 516 | if (next != '\n') { |
| 517 | buf += next; |
| 518 | c = source->getc(); |
| 519 | if (c == '\n' || c == EOF) { |
| 520 | continue; |
| 521 | } |
| 522 | } else if (c == '"') { |
| 523 | break; |
| 524 | } else { |
| 525 | buf += c; |
| 526 | } |
| 527 | value += c; |
| 528 | } |
| 529 | |
| 530 | if (c == EOF) { |
| 531 | cerr << "Reached EOF before closing \" in value." << endl; |
| 532 | } |
| 533 | |
| 534 | value = buf; |
| 535 | |
| 536 | return false; |
| 537 | // If the value is empty, parse_entry_finish() might later just skip |
| 538 | // the complete entry. To allow empty config options we add a dummy space. |
| 539 | if (!value.size()) { |
| 540 | value = " "; |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | //! @brief Parses entry (name + value) and executes command accordingly. |
| ... | |
| src/CfgParser.hh | |
| 115 | @@ -115,7 +115,7 @@ |
| 115 | private: |
| 116 | void parse_source_new(const std::string &name, CfgParserSource::Type type); |
| 117 | bool parse_name(std::string &buf); |
| 118 | bool parse_value(CfgParserSource *source, std::string &value); |
| 119 | void parse_value(CfgParserSource *source, std::string &value); |
| 120 | void parse_entry_finish(std::string &buf, std::string &value); |
| 121 | void parse_entry_finish_standard(std::string &buf, std::string &value); |
| 122 | void parse_entry_finish_template(std::string &name); |
| ... | |