From 26c4d5ddef6920043ae40a9d80ca31f3b820bad5 Mon Sep 17 00:00:00 2001 From: Taylor King Date: Sun, 9 Oct 2016 12:05:23 -0400 Subject: 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 41b06ff..7922ab9 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 891fedf..53ed45f 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); }; -- cgit v1.2.3-54-g00ecf