comparison util/stanza.lua @ 12725:12ced5db29b2

Merge 0.12->trunk
author Kim Alvefur <zash@zash.se>
date Thu, 15 Sep 2022 11:11:52 +0200
parents 5b69ecaf3427 5b5b428d67e2
children 4a8740e01813
comparison
equal deleted inserted replaced
12723:4cfd09343947 12725:12ced5db29b2
165 or child.attr.xmlns == xmlns) then 165 or child.attr.xmlns == xmlns) then
166 166
167 return child; 167 return child;
168 end 168 end
169 end 169 end
170 return nil;
170 end 171 end
171 172
172 function stanza_mt:get_child_text(name, xmlns) 173 function stanza_mt:get_child_text(name, xmlns)
173 local tag = self:get_child(name, xmlns); 174 local tag = self:get_child(name, xmlns);
174 if tag then 175 if tag then
187 188
188 function stanza_mt:child_with_name(name) 189 function stanza_mt:child_with_name(name)
189 for _, child in ipairs(self.tags) do 190 for _, child in ipairs(self.tags) do
190 if child.name == name then return child; end 191 if child.name == name then return child; end
191 end 192 end
193 return nil;
192 end 194 end
193 195
194 function stanza_mt:child_with_ns(ns) 196 function stanza_mt:child_with_ns(ns)
195 for _, child in ipairs(self.tags) do 197 for _, child in ipairs(self.tags) do
196 if child.attr.xmlns == ns then return child; end 198 if child.attr.xmlns == ns then return child; end
197 end 199 end
200 return nil;
198 end 201 end
199 202
200 function stanza_mt:get_child_with_attr(name, xmlns, attr_name, attr_value, normalize) 203 function stanza_mt:get_child_with_attr(name, xmlns, attr_name, attr_value, normalize)
201 for tag in self:childtags(name, xmlns) do 204 for tag in self:childtags(name, xmlns) do
202 if (normalize and normalize(tag.attr[attr_name]) or tag.attr[attr_name]) == attr_value then 205 if (normalize and normalize(tag.attr[attr_name]) or tag.attr[attr_name]) == attr_value then
203 return tag; 206 return tag;
204 end 207 end
205 end 208 end
209 return nil;
206 end 210 end
207 211
208 function stanza_mt:children() 212 function stanza_mt:children()
209 local i = 0; 213 local i = 0;
210 return function (a) 214 return function (a)
367 371
368 function stanza_mt.get_text(t) 372 function stanza_mt.get_text(t)
369 if #t.tags == 0 then 373 if #t.tags == 0 then
370 return t_concat(t); 374 return t_concat(t);
371 end 375 end
376 return nil;
372 end 377 end
373 378
374 function stanza_mt.get_error(stanza) 379 function stanza_mt.get_error(stanza)
375 local error_type, condition, text, extra_tag; 380 local error_type, condition, text, extra_tag;
376 381