Add UniValue::find_value method

This commit is contained in:
MarcoFalke committed 2023-05-09 18:47:14 +02:00
1 parent fc06881f13
commit fa548ac872
2 files changed
+8 -7

No files matched your search

+2 -2
View File
@@ -123,7 +123,7 @@ public:
const UniValue& get_array() const;
enum VType type() const { return getType(); }
friend const UniValue& find_value( const UniValue& obj, const std::string& name);
const UniValue& find_value(std::string_view key) const;
};
template <class It>
@@ -201,6 +201,6 @@ static inline bool json_isspace(int ch)
extern const UniValue NullUniValue;
const UniValue& find_value( const UniValue& obj, const std::string& name);
inline const UniValue& find_value(const UniValue& obj, const std::string& name) { return obj.find_value(name); }
#endif // BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_H
+6 -5
View File
@@ -230,12 +230,13 @@ const char *uvTypeName(UniValue::VType t)
return nullptr;
}
const UniValue& find_value(const UniValue& obj, const std::string& name)
const UniValue& UniValue::find_value(std::string_view key) const
{
for (unsigned int i = 0; i < obj.keys.size(); i++)
if (obj.keys[i] == name)
return obj.values.at(i);
for (unsigned int i = 0; i < keys.size(); ++i) {
if (keys[i] == key) {
return values.at(i);
}
}
return NullUniValue;
}