Simplify json.keys()

This commit is contained in:
ipknHama 2017-09-18 01:21:03 +09:00
parent 6da6579ce9
commit 9c26e1ebde

View File

@ -1333,23 +1333,17 @@ namespace crow
return (*o)[str]; return (*o)[str];
} }
std::vector<std::string> keys() const { std::vector<std::string> keys() const
{
if (t_ != type::Object)
return {};
std::vector<std::string> result; std::vector<std::string> result;
switch (t_) { for (auto& kv:*o)
case type::Null: return result; {
case type::False: return result;
case type::True: return result;
case type::Number: return result;
case type::String: return result;
case type::List: return result;
case type::Object: {
for (auto& kv:*o) {
result.push_back(kv.first); result.push_back(kv.first);
} }
return result; return result;
} }
}
}
size_t estimate_length() const size_t estimate_length() const
{ {