Skip to content
Snippets Groups Projects
Commit ee20bb97 authored by Bienchen's avatar Bienchen
Browse files

Allow whitespaces in front of Star-formated lines

parent eebc74f3
No related branches found
No related tags found
No related merge requests found
//------------------------------------------------------------------------------
// This file is part of the OpenStructure project <www.openstructure.org>
//
// Copyright (C) 2008-2020 by the OpenStructure authors
// Copyright (C) 2008-2024 by the OpenStructure authors
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
......@@ -257,7 +257,7 @@ void StarParser::ParseLoop()
StarLoopDesc header;
this->ConsumeLine();
while (this->GetLine(line)) {
StringRef tline=line.rtrim();
StringRef tline=line.trim();
if (tline.empty()) {
this->ConsumeLine();
continue;
......@@ -301,22 +301,29 @@ void StarParser::ParseLoop()
this->ConsumeLine();
continue;
}
switch (tline[0]) {
case '#':
this->ConsumeLine();
break;
case ';':
/*
To deal with lines starting with whitespaces, move parsing multi-line
values out of the switch..case construct. Multi-line values starting
with ';' must not have leading whitespace(s).
*/
if ( tline[0]==';') {
if (process_rows) {
tmp_values.push_back(String());
this->ParseMultilineValue(tmp_values.back());
if (tmp_values.size()==header.GetSize()) {
this->CallOnDataRow(header, tmp_values);
tmp_values.clear();
}
}
} else {
String s;
this->ParseMultilineValue(s, true);
}
continue;
}
tline=tline.ltrim();
switch (tline[0]) {
case '#':
this->ConsumeLine();
break;
case '_':
return;
......@@ -342,7 +349,7 @@ void StarParser::ParseLoop()
}
this->ConsumeLine();
break;
}
}
}
if (process_rows) {
this->OnEndLoop();
......@@ -476,6 +483,20 @@ void StarParser::ParseData()
this->ConsumeLine();
continue;
}
/*
To deal with lines starting with whitespaces, move parsing multi-line
values out of the switch..case construct. Multi-line values starting
with ';' must not have leading whitespace(s).
*/
if (tline[0]==';') {
if (skip) {
String s;
this->ParseMultilineValue(s, true);
}
continue;
}
tline=tline.ltrim();
switch (tline[0]) {
case '_':
if (skip) {
......@@ -490,12 +511,6 @@ void StarParser::ParseData()
this->OnEndData();
return;
}
case ';':
if (skip) {
String s;
this->ParseMultilineValue(s, true);
}
break;
case 'l':
if (tline==StringRef("loop_", 5)) {
this->ParseEndDataItemRow();
......@@ -541,7 +556,7 @@ void StarParser::Parse()
StringRef line;
std::stringstream ss;
while (this->GetLine(line)) {
StringRef tline=line.rtrim();
StringRef tline=line.trim();
if (tline.empty()) {
this->ConsumeLine();
continue;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment