Allow using string view to find JSON value. (#8332)

- Allow comparison between string and string view.
- Fix compiler warnings.
This commit is contained in:
Jiaming Yuan
2022-10-13 17:10:13 +08:00
committed by GitHub
parent 29595102b9
commit 3ef1703553
8 changed files with 109 additions and 107 deletions

View File

@@ -258,7 +258,7 @@ void TypeCheck(Json const &value, StringView name) {
}
template <typename JT>
auto const &RequiredArg(Json const &in, std::string const &key, StringView func) {
auto const &RequiredArg(Json const &in, StringView key, StringView func) {
auto const &obj = get<Object const>(in);
auto it = obj.find(key);
if (it == obj.cend() || IsA<Null>(it->second)) {
@@ -269,11 +269,11 @@ auto const &RequiredArg(Json const &in, std::string const &key, StringView func)
}
template <typename JT, typename T>
auto const &OptionalArg(Json const &in, std::string const &key, T const &dft) {
auto const &OptionalArg(Json const &in, StringView key, T const &dft) {
auto const &obj = get<Object const>(in);
auto it = obj.find(key);
if (it != obj.cend() && !IsA<Null>(it->second)) {
TypeCheck<JT>(it->second, StringView{key});
TypeCheck<JT>(it->second, key);
return get<std::remove_const_t<JT> const>(it->second);
}
return dft;