From f2e89f40f921cd618a3c4c9f289810db93989dcf Mon Sep 17 00:00:00 2001 From: Wouter Scherphof Date: Tue, 26 Mar 2013 10:28:33 +0100 Subject: [PATCH] string.gsub FTW --- ElementNode.lua | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/ElementNode.lua b/ElementNode.lua index 92c5789..e78c45b 100644 --- a/ElementNode.lua +++ b/ElementNode.lua @@ -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)