Comparison

core/xmlhandlers.lua @ 2463:d9ff0190eb4a

xmlhandlers: Define ns_separator and ns_pattern to save repeating it in literal form throughout the file
author Matthew Wild <mwild1@gmail.com>
date Mon, 18 Jan 2010 19:00:18 +0000
parent 2261:13d55c66bf81
child 2464:0b5f0ae7a6b1
comparison
equal deleted inserted replaced
2462:2d81cc25b5a6 2463:d9ff0190eb4a
24 module "xmlhandlers" 24 module "xmlhandlers"
25 25
26 local ns_prefixes = { 26 local ns_prefixes = {
27 ["http://www.w3.org/XML/1998/namespace"] = "xml"; 27 ["http://www.w3.org/XML/1998/namespace"] = "xml";
28 } 28 }
29 local ns_separator = "\1";
30 local ns_pattern = "^([^"..ns_separator.."]*)"..ns_separator.."?(.*)$";
29 31
30 function init_xmlhandlers(session, stream_callbacks) 32 function init_xmlhandlers(session, stream_callbacks)
31 local ns_stack = { "" }; 33 local ns_stack = { "" };
32 local curr_tag; 34 local curr_tag;
33 local chardata = {}; 35 local chardata = {};
47 if stanza and #chardata > 0 then 49 if stanza and #chardata > 0 then
48 -- We have some character data in the buffer 50 -- We have some character data in the buffer
49 stanza:text(t_concat(chardata)); 51 stanza:text(t_concat(chardata));
50 chardata = {}; 52 chardata = {};
51 end 53 end
52 local curr_ns,name = tagname:match("^([^\1]*)\1?(.*)$"); 54 local curr_ns,name = tagname:match(ns_pattern);
53 if name == "" then 55 if name == "" then
54 curr_ns, name = "", curr_ns; 56 curr_ns, name = "", curr_ns;
55 end 57 end
56 58
57 if curr_ns ~= stream_default_ns then 59 if curr_ns ~= stream_default_ns then
60 62
61 -- FIXME !!!!! 63 -- FIXME !!!!!
62 for i=1,#attr do 64 for i=1,#attr do
63 local k = attr[i]; 65 local k = attr[i];
64 attr[i] = nil; 66 attr[i] = nil;
65 local ns, nm = k:match("^([^\1]*)\1?(.*)$"); 67 local ns, nm = k:match(ns_pattern);
66 if nm ~= "" then 68 if nm ~= "" then
67 ns = ns_prefixes[ns]; 69 ns = ns_prefixes[ns];
68 if ns then 70 if ns then
69 attr[ns..":"..nm] = attr[k]; 71 attr[ns..":"..nm] = attr[k];
70 attr[k] = nil; 72 attr[k] = nil;
102 if stanza then 104 if stanza then
103 t_insert(chardata, data); 105 t_insert(chardata, data);
104 end 106 end
105 end 107 end
106 function xml_handlers:EndElement(tagname) 108 function xml_handlers:EndElement(tagname)
107 local curr_ns,name = tagname:match("^([^\1]*)\1?(.*)$"); 109 local curr_ns,name = tagname:match(ns_pattern);
108 if name == "" then 110 if name == "" then
109 curr_ns, name = "", curr_ns; 111 curr_ns, name = "", curr_ns;
110 end 112 end
111 if (not stanza) or (#stanza.last_add > 0 and name ~= stanza.last_add[#stanza.last_add].name) then 113 if (not stanza) or (#stanza.last_add > 0 and name ~= stanza.last_add[#stanza.last_add].name) then
112 if tagname == stream_tag then 114 if tagname == stream_tag then