Mercurial > prosody-hg
comparison util/stanza.lua @ 8998:6bddc90eeb27
util.stanza: Add method for removing all children with a specific name, xmlns
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 08 Jul 2018 16:48:59 +0200 |
| parents | e58524240b30 |
| children | a2a4c225a3f8 |
comparison
equal
deleted
inserted
replaced
| 8991:37ebcc7c6768 | 8998:6bddc90eeb27 |
|---|---|
| 95 local last_add = self.last_add; | 95 local last_add = self.last_add; |
| 96 (last_add and last_add[#last_add] or self):add_direct_child(child); | 96 (last_add and last_add[#last_add] or self):add_direct_child(child); |
| 97 return self; | 97 return self; |
| 98 end | 98 end |
| 99 | 99 |
| 100 function stanza_mt:remove_children(name, xmlns) | |
| 101 xmlns = xmlns or self.attr.xmlns; | |
| 102 return self:maptags(function (tag) | |
| 103 if (not name or tag.name == name) and tag.attr.xmlns == xmlns then | |
| 104 return nil; | |
| 105 end | |
| 106 return tag; | |
| 107 end); | |
| 108 end | |
| 109 | |
| 100 function stanza_mt:get_child(name, xmlns) | 110 function stanza_mt:get_child(name, xmlns) |
| 101 for _, child in ipairs(self.tags) do | 111 for _, child in ipairs(self.tags) do |
| 102 if (not name or child.name == name) | 112 if (not name or child.name == name) |
| 103 and ((not xmlns and self.attr.xmlns == child.attr.xmlns) | 113 and ((not xmlns and self.attr.xmlns == child.attr.xmlns) |
| 104 or child.attr.xmlns == xmlns) then | 114 or child.attr.xmlns == xmlns) then |
