Changeset

3474:730876bbe4e6

util.stanza: Add stanza:matched_children(name, xmlns) [name suggestions welcome]
author Matthew Wild <mwild1@gmail.com>
date Sun, 29 Aug 2010 15:04:34 +0100
parents 3473:84fe4d5ac2ed
children 3475:0307a3ac3885
files util/stanza.lua
diffstat 1 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/util/stanza.lua	Sat Aug 28 23:41:09 2010 +0100
+++ b/util/stanza.lua	Sun Aug 29 15:04:34 2010 +0100
@@ -126,6 +126,23 @@
 			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)