diff options
author | Taylor King <taylor@Taylors-MacBook-Pro.local> | 2016-10-09 12:05:23 -0400 |
---|---|---|
committer | Taylor King <kingtb@appstate.edu> | 2016-10-10 06:10:01 -0400 |
commit | 26c4d5ddef6920043ae40a9d80ca31f3b820bad5 (patch) | |
tree | c363ed4c50f01f6325fbe7036c36d992d4deaf81 | |
parent | 4e39b23e455e455f1878b3e68d729a1737f3e431 (diff) | |
download | crow-26c4d5ddef6920043ae40a9d80ca31f3b820bad5.tar.gz crow-26c4d5ddef6920043ae40a9d80ca31f3b820bad5.zip |
implement .keys()
-rw-r--r-- | amalgamate/crow_all.h | 19 | ||||
-rw-r--r-- | 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<std::string> keys() const { + 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; + } + } + } + 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<std::string> keys() const { + 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; + } + } + } + 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); }; |