Comparison

util/stanza.lua @ 1931:f203330eb82e

util.stanza: Make xml_escape publicly accessible
author Matthew Wild <mwild1@gmail.com>
date Tue, 06 Oct 2009 18:05:31 +0100
parent 1874:262ea889016f
child 1932:af8cdbb63b13
comparison
equal deleted inserted replaced
1930:92b78dd346ca 1931:f203330eb82e
116 if v then return v; end 116 if v then return v; end
117 end, self.tags[1], i; 117 end, self.tags[1], i;
118 118
119 end 119 end
120 120
121 local xml_escape = (function() 121 local xml_escape
122 do
122 local escape_table = { ["'"] = "&apos;", ["\""] = "&quot;", ["<"] = "&lt;", [">"] = "&gt;", ["&"] = "&amp;" }; 123 local escape_table = { ["'"] = "&apos;", ["\""] = "&quot;", ["<"] = "&lt;", [">"] = "&gt;", ["&"] = "&amp;" };
123 return function(str) return (s_gsub(str, "['&<>\"]", escape_table)); end 124 function xml_escape(str) return (s_gsub(str, "['&<>\"]", escape_table)); end
124 end)(); 125 _M.xml_escape = xml_escape;
126 end
127
125 local function _dostring(t, buf, self, xml_escape) 128 local function _dostring(t, buf, self, xml_escape)
126 local nsid = 0; 129 local nsid = 0;
127 local name = t.name 130 local name = t.name
128 t_insert(buf, "<"..name); 131 t_insert(buf, "<"..name);
129 for k, v in pairs(t.attr) do 132 for k, v in pairs(t.attr) do