Skip to content
Snippets Groups Projects
Commit 471599cb authored by Studer Gabriel's avatar Studer Gabriel
Browse files

mmcif writer: use semi-colon when writing multiline values

parent 25561497
No related branches found
No related tags found
No related merge requests found
...@@ -125,11 +125,22 @@ public: ...@@ -125,11 +125,22 @@ public:
// * loop_ (case insensitive) // * loop_ (case insensitive)
// * stop_ (case insensitive) // * stop_ (case insensitive)
// * global_ (case insensitive) // * global_ (case insensitive)
bool is_multiline = false;
bool needs_quotes = false; bool needs_quotes = false;
// newline in string
for(char c: string_value) {
if(c == '\n') {
is_multiline = true;
break;
}
}
// space in string // space in string
for(char c: string_value) { for(char c: string_value) {
if(isspace(c)) { if(isspace(c) && c != '\n') {
// linebreaks evaluate to true in isspace but do not require quotes
needs_quotes = true; needs_quotes = true;
break; break;
} }
...@@ -219,9 +230,16 @@ public: ...@@ -219,9 +230,16 @@ public:
} }
} }
if(needs_quotes) { if(is_multiline && needs_quotes) {
value.value_ = "\n;\"" + string_value + "\"\n;\n";
}
else if(needs_quotes) {
value.value_ = "\"" + string_value + "\""; value.value_ = "\"" + string_value + "\"";
} else { }
else if(is_multiline) {
value.value_ = "\n;" + string_value + "\n;\n";
}
else {
value.value_ = string_value; value.value_ = string_value;
} }
} }
...@@ -315,9 +333,14 @@ public: ...@@ -315,9 +333,14 @@ public:
desc_.ToStream(s); desc_.ToStream(s);
int desc_size = desc_.GetSize(); int desc_size = desc_.GetSize();
for(size_t i = 0; i < data_.size(); ++i) { for(size_t i = 0; i < data_.size(); ++i) {
s << data_[i].GetValue(); const String& v = data_[i].GetValue();
s << v;
bool ends_with_newline = v.back() == '\n';
if((i+1) % desc_size == 0) { if((i+1) % desc_size == 0) {
s << std::endl; // no need for newline if the last item ended with a newline anyways
if(!ends_with_newline) {
s << std::endl;
}
} else { } else {
s << ' '; s << ' ';
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment