From 26c4d5ddef6920043ae40a9d80ca31f3b820bad5 Mon Sep 17 00:00:00 2001 From: Taylor King Date: Sun, 9 Oct 2016 12:05:23 -0400 Subject: [PATCH] implement .keys() --- amalgamate/crow_all.h | 19 ++++++++++++++++++- include/crow/json.h | 19 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/amalgamate/crow_all.h b/amalgamate/crow_all.h index 41b06ffb1..7922ab999 100644 --- a/amalgamate/crow_all.h +++ b/amalgamate/crow_all.h @@ -4698,6 +4698,24 @@ namespace crow return (*o)[str]; } + std::vector keys() const { + 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; + } + } + } + size_t estimate_length() const { switch(t_) @@ -4738,7 +4756,6 @@ namespace crow return 1; } - friend void dump_internal(const wvalue& v, std::string& out); friend std::string dump(const wvalue& v); }; diff --git a/include/crow/json.h b/include/crow/json.h index 891fedfcb..53ed45fa0 100644 --- a/include/crow/json.h +++ b/include/crow/json.h @@ -1316,6 +1316,24 @@ namespace crow return (*o)[str]; } + std::vector keys() const { + 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; + } + } + } + size_t estimate_length() const { switch(t_) @@ -1356,7 +1374,6 @@ namespace crow return 1; } - friend void dump_internal(const wvalue& v, std::string& out); friend std::string dump(const wvalue& v); };