Skip to content

Commit

Permalink
Function to unscape HTML XML entities
Browse files Browse the repository at this point in the history
  • Loading branch information
yagop committed Jun 21, 2015
1 parent f9b7a7f commit 3d250bc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions bot/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -508,3 +508,21 @@ function load_from_file(file, default_data)
end
return loadfile (file)()
end

-- See http://stackoverflow.com/a/14899740
function unescape_html(str)
local map = {
["lt"] = "<",
["gt"] = ">",
["amp"] = "&",
["quot"] = '"',
["apos"] = "'"
}
new = string.gsub(str, '(&(#?x?)([%d%a]+);)', function(orig, n, s)
var = map[s] or n == "#" and string.char(s)
var = var or n == "#x" and string.char(tonumber(s,16))
var = var or orig
return var
end)
return new
end

0 comments on commit 3d250bc

Please sign in to comment.