Comparison

util/vcard.lua @ 307:9d295d44a16e

util.vcard: Ignore undefined properties
author Kim Alvefur <zash@zash.se>
date Sun, 01 Jul 2012 13:54:09 +0200
parent 306:c6183b218f77
child 310:c3e2b95b5b0b
comparison
equal deleted inserted replaced
306:c6183b218f77 307:9d295d44a16e
225 end 225 end
226 226
227 local function from_xep54_item(item) 227 local function from_xep54_item(item)
228 local prop_name = item.name; 228 local prop_name = item.name;
229 local prop_def = vCard_dtd[prop_name]; 229 local prop_def = vCard_dtd[prop_name];
230 if not prop_def then return nil end
231 230
232 local prop = { name = prop_name }; 231 local prop = { name = prop_name };
233 232
234 if prop_def == "text" then 233 if prop_def == "text" then
235 prop[1] = item:get_text(); 234 prop[1] = item:get_text();
297 296
298 local function from_xep54_vCard(vCard) 297 local function from_xep54_vCard(vCard)
299 local tags = vCard.tags; 298 local tags = vCard.tags;
300 local t = {}; 299 local t = {};
301 for i=1,#tags do 300 for i=1,#tags do
302 t[i] = from_xep54_item(tags[i]); 301 t_insert(t, from_xep54_item(tags[i]));
303 end 302 end
304 return t 303 return t
305 end 304 end
306 305
307 function from_xep54(vCard) 306 function from_xep54(vCard)
310 end 309 end
311 if vCard.name == "xCard" then -- A collection of vCards 310 if vCard.name == "xCard" then -- A collection of vCards
312 local t = {}; 311 local t = {};
313 local vCards = vCard.tags; 312 local vCards = vCard.tags;
314 for i=1,#vCards do 313 for i=1,#vCards do
315 local ti = from_xep54_vCard(vCards[i]); 314 t[i] = from_xep54_vCard(vCards[i]);
316 t[i] = ti;
317 --t[ti.name] = ti;
318 end 315 end
319 return t 316 return t
320 elseif vCard.name == "vCard" then -- A single vCard 317 elseif vCard.name == "vCard" then -- A single vCard
321 return from_xep54_vCard(vCard) 318 return from_xep54_vCard(vCard)
322 end 319 end