From eba0bacfdaeaddd47c323f6681c79d57228d93a5 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 12 Sep 2021 10:31:02 +0100 Subject: util.stanza: Add :get_child_with_attr() + tests --- util/stanza.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'util/stanza.lua') diff --git a/util/stanza.lua b/util/stanza.lua index 7f321da8..d03558ce 100644 --- a/util/stanza.lua +++ b/util/stanza.lua @@ -191,6 +191,14 @@ function stanza_mt:child_with_ns(ns) end end +function stanza_mt:get_child_with_attr(name, xmlns, attr_name, attr_value, normalize) + for tag in self:childtags(name, xmlns) do + if (normalize and normalize(tag.attr[attr_name]) or tag.attr[attr_name]) == attr_value then + return tag; + end + end +end + function stanza_mt:children() local i = 0; return function (a) -- cgit v1.2.3