mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-18 02:08: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 << ", ";}
|
if(!is_first) {std::cout << ", ";}
|
||||||
is_first = false;
|
is_first = false;
|
||||||
std::cout << toml::format(toml::value(elem.first),
|
std::cout << this->format_key(elem.first) << ':';
|
||||||
std::numeric_limits<std::size_t>::max());
|
|
||||||
std::cout << ':';
|
|
||||||
toml::visit(*this, elem.second);
|
toml::visit(*this, elem.second);
|
||||||
}
|
}
|
||||||
std::cout << '}';
|
std::cout << '}';
|
||||||
@@ -112,6 +110,12 @@ struct json_serializer
|
|||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string format_key(const std::string& s) const
|
||||||
|
{
|
||||||
|
const auto quote("\"");
|
||||||
|
return quote + escape_string(s) + quote;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
Reference in New Issue
Block a user