mirror of
https://github.com/ToruNiina/toml11.git
synced 2024-11-25 22:00:05 +00:00
refactor: distinguish the reason of failure
This commit is contained in:
parent
fd50b11523
commit
fce6ff317e
@ -595,7 +595,9 @@ struct serializer
|
|||||||
token += format_key(keys_.back());
|
token += format_key(keys_.back());
|
||||||
token += " = ";
|
token += " = ";
|
||||||
}
|
}
|
||||||
bool failed = false;
|
|
||||||
|
bool exceed_column = false;
|
||||||
|
bool has_comment = false;
|
||||||
token += "[\n";
|
token += "[\n";
|
||||||
for(const auto& item : v)
|
for(const auto& item : v)
|
||||||
{
|
{
|
||||||
@ -603,7 +605,7 @@ struct serializer
|
|||||||
// cannot be inlined.
|
// cannot be inlined.
|
||||||
if(this->has_comment_inside(item.as_table()))
|
if(this->has_comment_inside(item.as_table()))
|
||||||
{
|
{
|
||||||
failed = true;
|
has_comment = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// write comments for the table itself
|
// write comments for the table itself
|
||||||
@ -614,13 +616,13 @@ struct serializer
|
|||||||
if(t.size() + 1 > width_ || // +1 for the last comma {...},
|
if(t.size() + 1 > width_ || // +1 for the last comma {...},
|
||||||
std::find(t.cbegin(), t.cend(), '\n') != t.cend())
|
std::find(t.cbegin(), t.cend(), '\n') != t.cend())
|
||||||
{
|
{
|
||||||
failed = true;
|
exceed_column = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
token += t;
|
token += t;
|
||||||
token += ",\n";
|
token += ",\n";
|
||||||
}
|
}
|
||||||
if(!failed)
|
if(!exceed_column && !has_comment)
|
||||||
{
|
{
|
||||||
token += "]\n";
|
token += "]\n";
|
||||||
return token;
|
return token;
|
||||||
|
Loading…
Reference in New Issue
Block a user