From 3cbdf9478a18f21e28c3bc196fed72e26ca87168 Mon Sep 17 00:00:00 2001 From: pixel Date: Mon, 11 Jun 2007 21:25:06 +0000 Subject: Adding some more code to the supportlib. --- lib/supportlib.lua | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/supportlib.lua b/lib/supportlib.lua index 8c53825..68c223c 100644 --- a/lib/supportlib.lua +++ b/lib/supportlib.lua @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: supportlib.lua,v 1.6 2007-05-31 16:02:34 pixel Exp $ */ +/* $Id: supportlib.lua,v 1.7 2007-06-11 21:25:06 pixel Exp $ */ ]]-- @@ -157,3 +157,32 @@ function split(str, at) return splut end + + +-- +-- String replacement functions. +-- + +local sql_replacements = { + { "\\", "\\\\" }, + { "'", "\\'" }, + { '"', '\\"' }, + { "\n", "\\n" }, + { "\r", "\\r" }, +-- { "\0", "\\0" }, + { "\026", "\\Z" }, +} + +function generic_escape(str, replacements) + local _, r + + for _, r in ipairs(replacements) do + str = string.gsub(str, r[1], r[2]) + end + + return str +end + +function sql_escape(name) + return generic_escape(name, sql_replacements) +end -- cgit v1.2.3