Software /
code /
prosody
Comparison
util/stanza.lua @ 11786:39164ea2ab9e
util.stanza: Add :get_child_with_attr() + tests
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 12 Sep 2021 10:31:02 +0100 |
parent | 11642:7f2dee4249aa |
child | 11960:12a3c05aa12d |
comparison
equal
deleted
inserted
replaced
11785:b1381e302cab | 11786:39164ea2ab9e |
---|---|
186 end | 186 end |
187 | 187 |
188 function stanza_mt:child_with_ns(ns) | 188 function stanza_mt:child_with_ns(ns) |
189 for _, child in ipairs(self.tags) do | 189 for _, child in ipairs(self.tags) do |
190 if child.attr.xmlns == ns then return child; end | 190 if child.attr.xmlns == ns then return child; end |
191 end | |
192 end | |
193 | |
194 function stanza_mt:get_child_with_attr(name, xmlns, attr_name, attr_value, normalize) | |
195 for tag in self:childtags(name, xmlns) do | |
196 if (normalize and normalize(tag.attr[attr_name]) or tag.attr[attr_name]) == attr_value then | |
197 return tag; | |
198 end | |
191 end | 199 end |
192 end | 200 end |
193 | 201 |
194 function stanza_mt:children() | 202 function stanza_mt:children() |
195 local i = 0; | 203 local i = 0; |