aboutsummaryrefslogtreecommitdiff
path: root/src/univalue
diff options
context:
space:
mode:
authorMarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>2023-05-09 09:21:37 +0200
committerMarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>2023-05-09 18:47:14 +0200
commitfa548ac872c094edc94c2afda5cc9b0d84f73af0 (patch)
treee59fe9c9143e6515c3ecb4ba12ae154d2be69ef6 /src/univalue
parentfc06881f13495154c888a64a38c7d538baf00435 (diff)
Add UniValue::find_value method
Diffstat (limited to 'src/univalue')
-rw-r--r--src/univalue/include/univalue.h4
-rw-r--r--src/univalue/lib/univalue.cpp11
2 files changed, 8 insertions, 7 deletions
diff --git a/src/univalue/include/univalue.h b/src/univalue/include/univalue.h
index d501c3fb69..621e9f8025 100644
--- a/src/univalue/include/univalue.h
+++ b/src/univalue/include/univalue.h
@@ -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
diff --git a/src/univalue/lib/univalue.cpp b/src/univalue/lib/univalue.cpp
index 5aa39edb75..c3d19caae0 100644
--- a/src/univalue/lib/univalue.cpp
+++ b/src/univalue/lib/univalue.cpp
@@ -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;
}