diff options
author | Matthew Wild <mwild1@gmail.com> | 2010-08-29 15:04:34 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2010-08-29 15:04:34 +0100 |
commit | aa509f9fced444535e69471224c1b5df70b31e6f (patch) | |
tree | a51eb12bd759f73c02f5d152e3a27610a76683f0 | |
parent | fc62af2024baf14005057460d028d97f4147767a (diff) | |
download | prosody-aa509f9fced444535e69471224c1b5df70b31e6f.tar.gz prosody-aa509f9fced444535e69471224c1b5df70b31e6f.zip |
util.stanza: Add stanza:matched_children(name, xmlns) [name suggestions welcome]
-rw-r--r-- | util/stanza.lua | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/util/stanza.lua b/util/stanza.lua index 08ef2c9a..e787cacf 100644 --- a/util/stanza.lua +++ b/util/stanza.lua @@ -126,6 +126,23 @@ function stanza_mt:children() if v then return v; end end, self, i; end + +function stanza_mt:matched_children(name, xmlns) + xmlns = xmlns or self.attr.xmlns; + local tags = self.tags; + local start_i, max_i = 1, #tags; + return function () + for i=start_i,max_i do + v = tags[i]; + if (not name or v.name == name) + and (not xmlns or xmlns == v.attr.xmlns) then + start_i = i+1; + return v; + end + end + end, tags, i; +end + function stanza_mt:childtags() local i = 0; return function (a) |