summaryrefslogtreecommitdiff
path: root/Libraries/LibHTML/TreeNode.h
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-10-19 18:14:54 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-10-19 18:14:54 +0200
commitb3a63e1d503f3b837d62abc990d290112aab69cf (patch)
treee0ea9debd3b694a0459c7bec4ede9c1542be79a1 /Libraries/LibHTML/TreeNode.h
parent8acc61f19ac35645abf286fc5751420784ddd3b3 (diff)
downloadserenity-b3a63e1d503f3b837d62abc990d290112aab69cf.zip
LibHTML: Add TreeNode<T>::for_each_in_subtree(callback)
This helper invokes a callback for the node and each of its descendants in pre-order.
Diffstat (limited to 'Libraries/LibHTML/TreeNode.h')
-rw-r--r--Libraries/LibHTML/TreeNode.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/Libraries/LibHTML/TreeNode.h b/Libraries/LibHTML/TreeNode.h
index 3adf8695f7..229b07c4e2 100644
--- a/Libraries/LibHTML/TreeNode.h
+++ b/Libraries/LibHTML/TreeNode.h
@@ -53,6 +53,15 @@ public:
bool is_child_allowed(const T&) const { return true; }
+ template<typename Callback>
+ void for_each_in_subtree(Callback callback)
+ {
+ callback(static_cast<T&>(*this));
+ for (auto* child = first_child(); child; child = child->next_sibling()) {
+ child->for_each_in_subtree(callback);
+ }
+ }
+
protected:
TreeNode() {}