diff options
author | ipknHama <ipknhama@gmail.com> | 2017-09-18 01:21:03 +0900 |
---|---|---|
committer | ipknHama <ipknhama@gmail.com> | 2017-09-18 01:21:18 +0900 |
commit | 9c26e1ebdea1c43ac1a30a8f2ab83debc923cd56 (patch) | |
tree | 88fc0d5838102d1e5ceec20c9745a36978429277 | |
parent | 6da6579ce94a06f5389db62340b762fcb56f7c39 (diff) | |
download | crow-9c26e1ebdea1c43ac1a30a8f2ab83debc923cd56.tar.gz crow-9c26e1ebdea1c43ac1a30a8f2ab83debc923cd56.zip |
Simplify json.keys()
-rw-r--r-- | include/crow/json.h | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/include/crow/json.h b/include/crow/json.h index 3d9ed18..d8dbace 100644 --- a/include/crow/json.h +++ b/include/crow/json.h @@ -1333,22 +1333,16 @@ namespace crow 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; - switch (t_) { - 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); - } - return result; - } + for (auto& kv:*o) + { + result.push_back(kv.first); } + return result; } size_t estimate_length() const |