util.stanza: Add stanza:matched_children(name, xmlns) [name suggestions welcome]
authorMatthew Wild <mwild1@gmail.com>
Sun, 29 Aug 2010 14:04:34 +0000 (15:04 +0100)
committerMatthew Wild <mwild1@gmail.com>
Sun, 29 Aug 2010 14:04:34 +0000 (15:04 +0100)
util/stanza.lua

index 08ef2c9aa1649deac35eca8fd38488e7982a5372..e787cacfe21fedcc6753d0a70ae3531e9e0853b5 100644 (file)
@@ -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)