Last active
March 6, 2017 11:53
-
-
Save Starfox64/f63f5df5907770e83519 to your computer and use it in GitHub Desktop.
Small library to process HTML entities in Garry's Mod.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
Entities list by Walter Cruz. | |
Library by _FR_Starfox64. | |
]]-- | |
htmlentities = {} | |
htmlentities.entities = { | |
[" "] = " ", | |
["¡"] = "¡", | |
["¢"] = "¢", | |
["£"] = "£", | |
["¤"] = "¤", | |
["¥"] = "¥", | |
["¦"] = "¦", | |
["§"] = "§", | |
["¨"] = "¨", | |
["©"] = "©", | |
["ª"] = "ª", | |
["«"] = "«", | |
["¬"] = "¬", | |
[""] = "­", | |
["®"] = "®", | |
["¯"] = "¯", | |
["°"] = "°", | |
["±"] = "±", | |
["²"] = "²", | |
["³"] = "³", | |
["´"] = "´", | |
["µ"] = "µ", | |
["¶"] = "¶", | |
["·"] = "·", | |
["¸"] = "¸", | |
["¹"] = "¹", | |
["º"] = "º", | |
["»"] = "»", | |
["¼"] = "¼", | |
["½"] = "½", | |
["¾"] = "¾", | |
["¿"] = "¿", | |
["À"] = "À", | |
["Á"] = "Á", | |
["Â"] = "Â", | |
["Ã"] = "Ã", | |
["Ä"] = "Ä", | |
["Å"] = "Å", | |
["Æ"] = "Æ", | |
["Ç"] = "Ç", | |
["È"] = "È", | |
["É"] = "É", | |
["Ê"] = "Ê", | |
["Ë"] = "Ë", | |
["Ì"] = "Ì", | |
["Í"] = "Í", | |
["Î"] = "Î", | |
["Ï"] = "Ï", | |
["Ð"] = "Ð", | |
["Ñ"] = "Ñ", | |
["Ò"] = "Ò", | |
["Ó"] = "Ó", | |
["Ô"] = "Ô", | |
["Õ"] = "Õ", | |
["Ö"] = "Ö", | |
["×"] = "×", | |
["Ø"] = "Ø", | |
["Ù"] = "Ù", | |
["Ú"] = "Ú", | |
["Û"] = "Û", | |
["Ü"] = "Ü", | |
["Ý"] = "Ý", | |
["Þ"] = "Þ", | |
["ß"] = "ß", | |
["à"] = "à", | |
["á"] = "á", | |
["â"] = "â", | |
["ã"] = "ã", | |
["ä"] = "ä", | |
["å"] = "å", | |
["æ"] = "æ", | |
["ç"] = "ç", | |
["è"] = "è", | |
["é"] = "é", | |
["ê"] = "ê", | |
["ë"] = "ë", | |
["ì"] = "ì", | |
["í"] = "í", | |
["î"] = "î", | |
["ï"] = "ï", | |
["ð"] = "ð", | |
["ñ"] = "ñ", | |
["ò"] = "ò", | |
["ó"] = "ó", | |
["ô"] = "ô", | |
["õ"] = "õ", | |
["ö"] = "ö", | |
["÷"] = "÷", | |
["ø"] = "ø", | |
["ù"] = "ù", | |
["ú"] = "ú", | |
["û"] = "û", | |
["ü"] = "ü", | |
["ý"] = "ý", | |
["þ"] = "þ", | |
["ÿ"] = "ÿ", | |
["\""] = """, | |
["\'"] = "'", | |
["<"] = "<", | |
[">"] = ">", | |
["&"] = "&" | |
} | |
htmlentities.entsToSymbols = {} | |
for symbol, ent in pairs( htmlentities.entities ) do | |
htmlentities.entsToSymbols[ ent ] = symbol | |
end | |
--[[ | |
Converts HTML Entities into their proper symbol. | |
@arg1-> string to process | |
@return-> processed string | |
]]-- | |
function htmlentities.encode( text ) | |
return (string.gsub( text, ".", htmlentities.entities )) | |
end | |
--[[ | |
Converts text into properly encoded HTML Entities. | |
@arg1-> string to process | |
@return-> processed string | |
]]-- | |
function htmlentities.decode( text ) | |
return (string.gsub( text, "&.-;", function(ent) | |
if htmlentities.entsToSymbols[ent] then | |
return htmlentities.entsToSymbols[ent] | |
end | |
end)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment