From 83f78e7fe6c7464d969422cbfb7a12f5fad77c2a Mon Sep 17 00:00:00 2001 From: Timo Nicolai Date: Wed, 19 Apr 2023 14:11:39 +0200 Subject: [PATCH] base: add Xml_node::for_each_attribute Adds a function that allows iterating over an XML node's attributes without relying on `Xml_node::Nonexistent_attribute`. Issue #4817 --- repos/base/include/util/xml_node.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/repos/base/include/util/xml_node.h b/repos/base/include/util/xml_node.h index 7dd4eefd0c..171e4d10d7 100644 --- a/repos/base/include/util/xml_node.h +++ b/repos/base/include/util/xml_node.h @@ -990,6 +990,26 @@ class Genode::Xml_node } } + /** + * Execute functor 'fn' for each attribute + */ + template + void for_each_attribute(FN const &fn) const + { + if (!_tags.start.has_attribute()) + return; + + for (Xml_attribute attr = _tags.start.attribute(); ; ) { + fn(attr); + + Token const next = attr._next_token(); + if (!Xml_attribute::_valid(next)) + return; + + attr = Xml_attribute(next); + } + } + /** * Return true if sub node of specified type exists */