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> // 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 // 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 // the terms of the GNU Lesser General Public License as published by the Free
...@@ -257,7 +257,7 @@ void StarParser::ParseLoop() ...@@ -257,7 +257,7 @@ void StarParser::ParseLoop()
StarLoopDesc header; StarLoopDesc header;
this->ConsumeLine(); this->ConsumeLine();
while (this->GetLine(line)) { while (this->GetLine(line)) {
StringRef tline=line.rtrim(); StringRef tline=line.trim();
if (tline.empty()) { if (tline.empty()) {
this->ConsumeLine(); this->ConsumeLine();
continue; continue;
...@@ -301,22 +301,29 @@ void StarParser::ParseLoop() ...@@ -301,22 +301,29 @@ void StarParser::ParseLoop()
this->ConsumeLine(); this->ConsumeLine();
continue; continue;
} }
switch (tline[0]) { /*
case '#': To deal with lines starting with whitespaces, move parsing multi-line
this->ConsumeLine(); values out of the switch..case construct. Multi-line values starting
break; with ';' must not have leading whitespace(s).
case ';': */
if ( tline[0]==';') {
if (process_rows) { if (process_rows) {
tmp_values.push_back(String()); tmp_values.push_back(String());
this->ParseMultilineValue(tmp_values.back()); this->ParseMultilineValue(tmp_values.back());
if (tmp_values.size()==header.GetSize()) { if (tmp_values.size()==header.GetSize()) {
this->CallOnDataRow(header, tmp_values); this->CallOnDataRow(header, tmp_values);
tmp_values.clear(); tmp_values.clear();
} }
} else { } else {
String s; String s;
this->ParseMultilineValue(s, true); this->ParseMultilineValue(s, true);
} }
continue;
}
tline=tline.ltrim();
switch (tline[0]) {
case '#':
this->ConsumeLine();
break; break;
case '_': case '_':
return; return;
...@@ -342,7 +349,7 @@ void StarParser::ParseLoop() ...@@ -342,7 +349,7 @@ void StarParser::ParseLoop()
} }
this->ConsumeLine(); this->ConsumeLine();
break; break;
} }
} }
if (process_rows) { if (process_rows) {
this->OnEndLoop(); this->OnEndLoop();
...@@ -476,6 +483,20 @@ void StarParser::ParseData() ...@@ -476,6 +483,20 @@ void StarParser::ParseData()
this->ConsumeLine(); this->ConsumeLine();
continue; 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]) { switch (tline[0]) {
case '_': case '_':
if (skip) { if (skip) {
...@@ -490,12 +511,6 @@ void StarParser::ParseData() ...@@ -490,12 +511,6 @@ void StarParser::ParseData()
this->OnEndData(); this->OnEndData();
return; return;
} }
case ';':
if (skip) {
String s;
this->ParseMultilineValue(s, true);
}
break;
case 'l': case 'l':
if (tline==StringRef("loop_", 5)) { if (tline==StringRef("loop_", 5)) {
this->ParseEndDataItemRow(); this->ParseEndDataItemRow();
...@@ -541,7 +556,7 @@ void StarParser::Parse() ...@@ -541,7 +556,7 @@ void StarParser::Parse()
StringRef line; StringRef line;
std::stringstream ss; std::stringstream ss;
while (this->GetLine(line)) { while (this->GetLine(line)) {
StringRef tline=line.rtrim(); StringRef tline=line.trim();
if (tline.empty()) { if (tline.empty()) {
this->ConsumeLine(); this->ConsumeLine();
continue; continue;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment