lua-users home
lua-l archive

Re: Shocking omission in the Kepler platform

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Yuri Takhteyev wrote:
I am wondering why you find this omission so shocking? When I ran
into the need for a function like this myself, I just added it in my
own app and moved on:
 function escape(text)
 return (text or ""):gsub("&", "&amp;"):gsub(">","&gt;"):gsub("<","&lt;")
 end
Or this alternative:
function escape(text)
 local escaped = { ['<']='&lt;', ['>']='&gt;', ["&"]='&amp;' }
 return text:gsub('[<>&]', function(c) return escaped[c] end)
end
print(escape('2 < 3 & 10 > 9'))

AltStyle によって変換されたページ (->オリジナル) /