Commit 8558f31b authored by twanvl's avatar twanvl

Whitespace skipping in Reader should not eat the newlines, previously it was...

Whitespace skipping in Reader should not eat the newlines, previously it was impossible to load a string containing "\n\n"
parent 5e11b54a
...@@ -234,13 +234,10 @@ void Reader::readLine(bool in_string) { ...@@ -234,13 +234,10 @@ void Reader::readLine(bool in_string) {
size_t pos = line.find_first_of(_(':'), indent); size_t pos = line.find_first_of(_(':'), indent);
if (trim(line).empty() || line.GetChar(indent) == _('#')) { if (trim(line).empty() || line.GetChar(indent) == _('#')) {
// empty line or comment // empty line or comment
if (input->Eof()) key.clear();
key.clear();
else // Recursion allows skipping of blank lines.
readLine(in_string);
return; return;
} }
key = line.substr(indent, pos - indent); key = line.substr(indent, pos - indent);
if (!ignore_invalid && !in_string && starts_with(key, _(" "))) { if (!ignore_invalid && !in_string && starts_with(key, _(" "))) {
warning(_("key: '") + key + _("' starts with a space; only use TABs for indentation!"), 0, false); warning(_("key: '") + key + _("' starts with a space; only use TABs for indentation!"), 0, false);
// try to fix up: 8 spaces is a tab // try to fix up: 8 spaces is a tab
...@@ -306,15 +303,19 @@ const String& Reader::getValue() { ...@@ -306,15 +303,19 @@ const String& Reader::getValue() {
} else if (value.empty()) { } else if (value.empty()) {
// a multiline string // a multiline string
previous_value.clear(); previous_value.clear();
bool first = true; int pending_newlines = 0;
// read all lines that are indented enough // read all lines that are indented enough
readLine(true); readLine(true);
previous_line_number = line_number; previous_line_number = line_number;
while (indent >= expected_indent && !input->Eof()) { while (indent >= expected_indent && !input->Eof()) {
if (!first) previous_value += _('\n'); previous_value.resize(previous_value.size() + pending_newlines, _('\n'));
first = false; pending_newlines = 0;
previous_value += line.substr(expected_indent); // strip expected indent previous_value += line.substr(expected_indent); // strip expected indent
readLine(true); do {
readLine(true);
pending_newlines++;
// skip empty lines that are not indented enough
} while(trim(line).empty() && indent < expected_indent && !input->Eof());
} }
// moveNext(), but without the initial readLine() // moveNext(), but without the initial readLine()
state = HANDLED; state = HANDLED;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment