Software /
code /
prosody
Comparison
util/stanza.lua @ 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 |
parent | 2961:db3c0ecce3f4 |
child | 3475:0307a3ac3885 |
comparison
equal
deleted
inserted
replaced
3473:84fe4d5ac2ed | 3474:730876bbe4e6 |
---|---|
124 i = i + 1 | 124 i = i + 1 |
125 local v = a[i] | 125 local v = a[i] |
126 if v then return v; end | 126 if v then return v; end |
127 end, self, i; | 127 end, self, i; |
128 end | 128 end |
129 | |
130 function stanza_mt:matched_children(name, xmlns) | |
131 xmlns = xmlns or self.attr.xmlns; | |
132 local tags = self.tags; | |
133 local start_i, max_i = 1, #tags; | |
134 return function () | |
135 for i=start_i,max_i do | |
136 v = tags[i]; | |
137 if (not name or v.name == name) | |
138 and (not xmlns or xmlns == v.attr.xmlns) then | |
139 start_i = i+1; | |
140 return v; | |
141 end | |
142 end | |
143 end, tags, i; | |
144 end | |
145 | |
129 function stanza_mt:childtags() | 146 function stanza_mt:childtags() |
130 local i = 0; | 147 local i = 0; |
131 return function (a) | 148 return function (a) |
132 i = i + 1 | 149 i = i + 1 |
133 local v = self.tags[i] | 150 local v = self.tags[i] |