From 9c26e1ebdea1c43ac1a30a8f2ab83debc923cd56 Mon Sep 17 00:00:00 2001 From: ipknHama Date: Mon, 18 Sep 2017 01:21:03 +0900 Subject: [PATCH] Simplify json.keys() --- include/crow/json.h | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/include/crow/json.h b/include/crow/json.h index 3d9ed1818..d8dbace7f 100644 --- a/include/crow/json.h +++ b/include/crow/json.h @@ -1333,22 +1333,16 @@ namespace crow return (*o)[str]; } - std::vector keys() const { + std::vector keys() const + { + if (t_ != type::Object) + return {}; std::vector 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