mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-18 02:08:09 +08:00
fix: add comma at correct position
This commit is contained in:
@@ -224,7 +224,10 @@ struct serializer
|
|||||||
token += "[\n";
|
token += "[\n";
|
||||||
for(const auto& item : v)
|
for(const auto& item : v)
|
||||||
{
|
{
|
||||||
const auto next_elem = toml::visit(*this, item);
|
auto next_elem = toml::visit(*this, item);
|
||||||
|
// newline between array-value and comma is not allowed
|
||||||
|
if(next_elem.back() == '\n'){next_elem.pop_back();}
|
||||||
|
|
||||||
if(current_line.size() + next_elem.size() + 1 < this->width_)
|
if(current_line.size() + next_elem.size() + 1 < this->width_)
|
||||||
{
|
{
|
||||||
current_line += next_elem;
|
current_line += next_elem;
|
||||||
@@ -235,14 +238,22 @@ struct serializer
|
|||||||
// the next elem cannot be within the width.
|
// the next elem cannot be within the width.
|
||||||
token += next_elem;
|
token += next_elem;
|
||||||
token += ",\n";
|
token += ",\n";
|
||||||
|
// keep current line empty
|
||||||
}
|
}
|
||||||
else
|
else // current_line has some tokens and it exceeds width
|
||||||
{
|
{
|
||||||
|
assert(current_line.back() == ',');
|
||||||
token += current_line;
|
token += current_line;
|
||||||
token += ",\n";
|
token += '\n';
|
||||||
current_line = next_elem;
|
current_line = next_elem;
|
||||||
|
current_line += ',';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(!current_line.empty())
|
||||||
|
{
|
||||||
|
if(current_line.back() != '\n') {current_line += '\n';}
|
||||||
|
token += current_line;
|
||||||
|
}
|
||||||
token += "]\n";
|
token += "]\n";
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user