mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-16 16:28:09 +08:00
test: use JSON format_key to format a key in JSON
The rule to format a basic string and a key is different. `"""` cannot be used with JSON keys. Also, toml key is basically not wrapped by `"`. So we need a function to format a key in JSON.
This commit is contained in:
@@ -84,9 +84,7 @@ struct json_serializer
|
||||
{
|
||||
if(!is_first) {std::cout << ", ";}
|
||||
is_first = false;
|
||||
std::cout << toml::format(toml::value(elem.first),
|
||||
std::numeric_limits<std::size_t>::max());
|
||||
std::cout << ':';
|
||||
std::cout << this->format_key(elem.first) << ':';
|
||||
toml::visit(*this, elem.second);
|
||||
}
|
||||
std::cout << '}';
|
||||
@@ -112,6 +110,12 @@ struct json_serializer
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
std::string format_key(const std::string& s) const
|
||||
{
|
||||
const auto quote("\"");
|
||||
return quote + escape_string(s) + quote;
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
|
Reference in New Issue
Block a user