From c4355eaa474cfa935c688b9631c563a027da48b6 Mon Sep 17 00:00:00 2001 From: Tristan Penman Date: Mon, 19 Sep 2022 21:01:08 +1000 Subject: [PATCH] Simplify implementation of YamlCppObject::find() --- include/valijson/adapters/yaml_cpp_adapter.hpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/include/valijson/adapters/yaml_cpp_adapter.hpp b/include/valijson/adapters/yaml_cpp_adapter.hpp index 44fc8a7..362d471 100644 --- a/include/valijson/adapters/yaml_cpp_adapter.hpp +++ b/include/valijson/adapters/yaml_cpp_adapter.hpp @@ -681,16 +681,13 @@ inline YamlCppObjectMemberIterator YamlCppObject::end() const inline YamlCppObjectMemberIterator YamlCppObject::find(const std::string &propertyName) const { - YAML::Node result = m_value[propertyName]; - if (!result.IsDefined()) - return end(); + for (auto itr = begin(); itr != end(); ++itr) { + if (itr->first == propertyName) { + return itr; + } + } - // yaml-cpp does not offer an iterator-based lookup, - // 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()); + return end(); } } // namespace adapters