mirror of
https://github.com/awesomeWM/awesome
synced 2024-11-18 22:06:01 +01:00
awful.util: optimize escape/unescape
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
62bbc395ab
commit
798943af31
1 changed files with 5 additions and 16 deletions
|
@ -94,29 +94,18 @@ end
|
|||
-- Useful to set raw text in textbox.
|
||||
-- @param text Text to escape.
|
||||
-- @return Escape text.
|
||||
local xml_entity_names = { ["'"] = "'", ["\""] = """, ["<"] = "<", [">"] = ">", ["&"] = "&" };
|
||||
function escape(text)
|
||||
if text then
|
||||
text = text:gsub("&", "&")
|
||||
text = text:gsub("<", "<")
|
||||
text = text:gsub(">", ">")
|
||||
text = text:gsub("'", "'")
|
||||
text = text:gsub("\"", """)
|
||||
end
|
||||
return text
|
||||
return text and text:gsub("['&<>\"]", xml_entity_names) or nil
|
||||
end
|
||||
|
||||
--- Unescape a string from entities.
|
||||
-- @param text Text to unescape.
|
||||
-- @return Unescaped text.
|
||||
|
||||
local xml_entity_chars = { lt = "<", gt = ">", nbsp = " ", quot = "\"", apos = "'", ndash = "-", mdash = "-", amp = "&" };
|
||||
function unescape(text)
|
||||
if text then
|
||||
text = text:gsub("&", "&")
|
||||
text = text:gsub("<", "<")
|
||||
text = text:gsub(">", ">")
|
||||
text = text:gsub("'", "'")
|
||||
text = text:gsub(""", "\"")
|
||||
end
|
||||
return text
|
||||
return text and text:gsub("&(%a+);", xml_entity_chars) or nil
|
||||
end
|
||||
|
||||
--- Check if a file is a Lua valid file.
|
||||
|
|
Loading…
Reference in a new issue