fix: use empty quoted string for empty key

This commit is contained in:
ToruNiina
2021-06-27 18:56:33 +09:00
parent 9d28afa012
commit 47a2a3332b

View File

@@ -29,6 +29,11 @@ template<typename charT, typename traits, typename Alloc>
std::basic_string<charT, traits, Alloc> std::basic_string<charT, traits, Alloc>
format_key(const std::basic_string<charT, traits, Alloc>& k) format_key(const std::basic_string<charT, traits, Alloc>& k)
{ {
if(k.empty())
{
return std::string("\"\"");
}
// check the key can be a bare (unquoted) key // check the key can be a bare (unquoted) key
detail::location loc(k, std::vector<char>(k.begin(), k.end())); detail::location loc(k, std::vector<char>(k.begin(), k.end()));
detail::lex_unquoted_key::invoke(loc); detail::lex_unquoted_key::invoke(loc);
@@ -61,9 +66,12 @@ template<typename charT, typename traits, typename Alloc>
std::basic_string<charT, traits, Alloc> std::basic_string<charT, traits, Alloc>
format_keys(const std::vector<std::basic_string<charT, traits, Alloc>>& keys) format_keys(const std::vector<std::basic_string<charT, traits, Alloc>>& keys)
{ {
std::basic_string<charT, traits, Alloc> serialized; if(keys.empty())
if(keys.empty()) {return serialized;} {
return std::string("\"\"");
}
std::basic_string<charT, traits, Alloc> serialized;
for(const auto& ky : keys) for(const auto& ky : keys)
{ {
serialized += format_key(ky); serialized += format_key(ky);