aboutsummaryrefslogtreecommitdiff
path: root/helpers.lua
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2009-08-03 04:29:06 +0200
committerAdrian C. (anrxc) <anrxc@sysphere.org>2009-08-03 04:29:06 +0200
commit09fda0ab05c066a8f630e1d7a36f401bbc0ca68e (patch)
tree9ba1d1fb528e867f9bb57208c878bae73f01bdcd /helpers.lua
parent047dba0e5d3aeedd7498c05135a924b980660d3e (diff)
downloadvicious-legacy-09fda0ab05c066a8f630e1d7a36f401bbc0ca68e.tar.xz
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.
Diffstat (limited to 'helpers.lua')
-rw-r--r--helpers.lua28
1 files changed, 14 insertions, 14 deletions
diff --git a/helpers.lua b/helpers.lua
index 875c14b..67319ed 100644
--- a/helpers.lua
+++ b/helpers.lua
@@ -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("&", "&amp;")
- text = text:gsub("<", "&lt;")
- text = text:gsub(">", "&gt;")
- text = text:gsub("'", "&apos;")
- text = text:gsub("\"", "&quot;")
- end
-
- return text
+ local xml_entities = {
+ ["\""] = "&quot;",
+ ["&"] = "&amp;",
+ ["'"] = "&apos;",
+ ["<"] = "&lt;",
+ [">"] = "&gt;"
+ }
+
+ return text and text:gsub("[\"&'<>]", xml_entities)
end
-- }}}
-- }}}