mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-12-16 03:08:52 +08:00
refactor: add write_comments()
This commit is contained in:
@@ -523,15 +523,8 @@ struct serializer
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!kv.second.comments().empty() && !no_comment_)
|
token += write_comments(kv.second);
|
||||||
{
|
|
||||||
for(const auto& c : kv.second.comments())
|
|
||||||
{
|
|
||||||
token += '#';
|
|
||||||
token += c;
|
|
||||||
token += '\n';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const auto key_and_sep = format_key(kv.first) + " = ";
|
const auto key_and_sep = format_key(kv.first) + " = ";
|
||||||
const auto residual_width = (this->width_ > key_and_sep.size()) ?
|
const auto residual_width = (this->width_ > key_and_sep.size()) ?
|
||||||
this->width_ - key_and_sep.size() : 0;
|
this->width_ - key_and_sep.size() : 0;
|
||||||
@@ -577,15 +570,7 @@ struct serializer
|
|||||||
tmp += '\n';
|
tmp += '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!kv.second.comments().empty() && !no_comment_)
|
token += write_comments(kv.second);
|
||||||
{
|
|
||||||
for(const auto& c : kv.second.comments())
|
|
||||||
{
|
|
||||||
token += '#';
|
|
||||||
token += c;
|
|
||||||
token += '\n';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
token += tmp;
|
token += tmp;
|
||||||
}
|
}
|
||||||
return token;
|
return token;
|
||||||
@@ -621,15 +606,8 @@ struct serializer
|
|||||||
failed = true;
|
failed = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(!no_comment_)
|
// write comments for the table itself
|
||||||
{
|
token += write_comments(item);
|
||||||
for(const auto& c : item.comments())
|
|
||||||
{
|
|
||||||
token += '#';
|
|
||||||
token += c;
|
|
||||||
token += '\n';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto t = this->make_inline_table(item.as_table());
|
const auto t = this->make_inline_table(item.as_table());
|
||||||
|
|
||||||
@@ -653,15 +631,7 @@ struct serializer
|
|||||||
std::string token;
|
std::string token;
|
||||||
for(const auto& item : v)
|
for(const auto& item : v)
|
||||||
{
|
{
|
||||||
if(!no_comment_)
|
token += write_comments(item);
|
||||||
{
|
|
||||||
for(const auto& c : item.comments())
|
|
||||||
{
|
|
||||||
token += '#';
|
|
||||||
token += c;
|
|
||||||
token += '\n';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
token += "[[";
|
token += "[[";
|
||||||
token += format_keys(keys_);
|
token += format_keys(keys_);
|
||||||
token += "]]\n";
|
token += "]]\n";
|
||||||
@@ -670,6 +640,20 @@ struct serializer
|
|||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string write_comments(const value_type& v) const
|
||||||
|
{
|
||||||
|
std::string retval;
|
||||||
|
if(this->no_comment_) {return retval;}
|
||||||
|
|
||||||
|
for(const auto& c : v.comments())
|
||||||
|
{
|
||||||
|
retval += '#';
|
||||||
|
retval += c;
|
||||||
|
retval += '\n';
|
||||||
|
}
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
bool is_array_of_tables(const value_type& v) const
|
bool is_array_of_tables(const value_type& v) const
|
||||||
{
|
{
|
||||||
if(!v.is_array()) {return false;}
|
if(!v.is_array()) {return false;}
|
||||||
|
|||||||
Reference in New Issue
Block a user