mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
Add UniValue::find_value method
This commit is contained in:
parent
fc06881f13
commit
fa548ac872
2 changed files with 8 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue