mirror of
https://github.com/msva/lua-htmlparser.git
synced 2024-11-04 23:34:20 +00:00
string.gsub FTW
This commit is contained in:
parent
6fdd415e91
commit
f2e89f40f9
@ -88,15 +88,8 @@ function ElementNode:close(closestart, closeend)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function escape(s)
|
local function escape(s)
|
||||||
local replace = {
|
-- escape all ^, $, (, ), %, ., [, ], *, +, - , and ? with a % prefix
|
||||||
["^"] = "%^", ["$"] = "%$", ["("] = "%(", [")"] = "%)", ["%"] = "%%", ["."] = "%.",
|
return string.gsub(s, "([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%" .. "%1")
|
||||||
["["] = "%[", ["]"] = "%]", ["*"] = "%*", ["+"] = "%+", ["-"] = "%-", ["?"] = "%?"
|
|
||||||
}
|
|
||||||
local res = ""
|
|
||||||
for c in string.gmatch(s, ".") do
|
|
||||||
res = res .. (replace[c] or c)
|
|
||||||
end
|
|
||||||
return res
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function select(self, s)
|
local function select(self, s)
|
||||||
|
Loading…
Reference in New Issue
Block a user