string.gsub FTW

This commit is contained in:
Wouter Scherphof 2013-03-26 10:28:33 +01:00
parent 6fdd415e91
commit f2e89f40f9

View File

@ -88,15 +88,8 @@ function ElementNode:close(closestart, closeend)
end
local function escape(s)
local replace = {
["^"] = "%^", ["$"] = "%$", ["("] = "%(", [")"] = "%)", ["%"] = "%%", ["."] = "%.",
["["] = "%[", ["]"] = "%]", ["*"] = "%*", ["+"] = "%+", ["-"] = "%-", ["?"] = "%?"
}
local res = ""
for c in string.gmatch(s, ".") do
res = res .. (replace[c] or c)
end
return res
-- escape all ^, $, (, ), %, ., [, ], *, +, - , and ? with a % prefix
return string.gsub(s, "([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%" .. "%1")
end
local function select(self, s)