Rewrite of the escape helper.

It is simillar to the awful.util.escape now, using a table which we
could expand (and rename) with other unwated characters if it comes to
that. I saw awesome break on many occasions because of encoding
problems.
This commit is contained in:
Adrian C. (anrxc) 2009-08-03 04:29:06 +02:00
parent 047dba0e5d
commit 09fda0ab05
1 changed files with 13 additions and 13 deletions

View File

@ -31,7 +31,7 @@ function format(format, args)
-- Format a string
for var, val in pairs(args) do
format = string.gsub(format, "$"..var, val)
format = string.gsub(format, "$" .. var, val)
end
-- Return formatted string
@ -49,7 +49,7 @@ function padd(number, padding)
for i=1, padding do
if math.floor(number/math.pow(10,(i-1))) == 0 then
s = "0"..s
s = "0" .. s
end
end
@ -88,28 +88,28 @@ function bytes_to_string(bytes, sec, padding)
if padding then
bytes = padd(bytes*10, padding+1)
bytes = bytes:sub(1, bytes:len()-1).."."..bytes:sub(bytes:len())
bytes = bytes:sub(1, bytes:len()-1) .. "." .. bytes:sub(bytes:len())
end
if sec then
return tostring(bytes)..signs[sign].."ps"
return tostring(bytes) .. signs[sign] .. "ps"
else
return tostring(bytes)..signs[sign]
return tostring(bytes) .. signs[sign]
end
end
-- }}}
--{{{ Escape a string
function escape(text)
if text then
text = text:gsub("&", "&")
text = text:gsub("<", "&lt;")
text = text:gsub(">", "&gt;")
text = text:gsub("'", "&apos;")
text = text:gsub("\"", "&quot;")
end
local xml_entities = {
["\""] = "&quot;",
["&"] = "&amp;",
["'"] = "&apos;",
["<"] = "&lt;",
[">"] = "&gt;"
}
return text
return text and text:gsub("[\"&'<>]", xml_entities)
end
-- }}}
-- }}}