quvi/util: Add escape_magic function
authorToni Gundogdu <legatvs@gmail.com>
Tue, 11 Jun 2013 06:46:07 +0000 (11 09:46 +0300)
committerToni Gundogdu <legatvs@gmail.com>
Tue, 11 Jun 2013 06:47:06 +0000 (11 09:47 +0300)
Signed-off-by: Toni Gundogdu <legatvs@gmail.com>
share/common/quvi/util.lua

index 5641c43..b7d416f 100644 (file)
@@ -146,6 +146,17 @@ function M.tokenize(s,sep) -- Based on http://lua-users.org/wiki/SplitJoin
   return fields
 end
 
+--[[
+Escape Lua magic characters.
+Parameters:
+  s .. String to escape
+Returns
+  The escaped string.
+]]--
+function M.escape_magic(s)
+  return (s:gsub('([()%%.%+%-*?[%]^$])', '%%%1'))
+end
+
 -- Uncomment to test
 --[[
 package.path = package.path .. ';../?.lua'