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
|
||||
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user