implement .keys()

This commit is contained in:
Taylor King 2016-10-09 12:05:23 -04:00 committed by Taylor King
parent 4e39b23e45
commit 26c4d5ddef
2 changed files with 36 additions and 2 deletions

View File

@ -4698,6 +4698,24 @@ namespace crow
return (*o)[str]; 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 size_t estimate_length() const
{ {
switch(t_) switch(t_)
@ -4738,7 +4756,6 @@ namespace crow
return 1; return 1;
} }
friend void dump_internal(const wvalue& v, std::string& out); friend void dump_internal(const wvalue& v, std::string& out);
friend std::string dump(const wvalue& v); friend std::string dump(const wvalue& v);
}; };

View File

@ -1316,6 +1316,24 @@ namespace crow
return (*o)[str]; 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 size_t estimate_length() const
{ {
switch(t_) switch(t_)
@ -1356,7 +1374,6 @@ namespace crow
return 1; return 1;
} }
friend void dump_internal(const wvalue& v, std::string& out); friend void dump_internal(const wvalue& v, std::string& out);
friend std::string dump(const wvalue& v); friend std::string dump(const wvalue& v);
}; };