mirror of
https://github.com/tristanpenman/valijson.git
synced 2025-01-06 00:31:11 +01:00
Simplify implementation of YamlCppObject::find()
This commit is contained in:
parent
375eaae06c
commit
c4355eaa47
@ -681,16 +681,13 @@ inline YamlCppObjectMemberIterator YamlCppObject::end() const
|
|||||||
inline YamlCppObjectMemberIterator
|
inline YamlCppObjectMemberIterator
|
||||||
YamlCppObject::find(const std::string &propertyName) const
|
YamlCppObject::find(const std::string &propertyName) const
|
||||||
{
|
{
|
||||||
YAML::Node result = m_value[propertyName];
|
for (auto itr = begin(); itr != end(); ++itr) {
|
||||||
if (!result.IsDefined())
|
if (itr->first == propertyName) {
|
||||||
return end();
|
return itr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// yaml-cpp does not offer an iterator-based lookup,
|
return end();
|
||||||
// so instead we create a new placeholder object and
|
|
||||||
// return an iterator to that container instead.
|
|
||||||
YAML::Node wrapper = YAML::Node(YAML::NodeType::Map);
|
|
||||||
wrapper[propertyName] = result;
|
|
||||||
return YamlCppObjectMemberIterator(wrapper.begin());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace adapters
|
} // namespace adapters
|
||||||
|
Loading…
Reference in New Issue
Block a user