summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpixel <pixel>2007-06-11 21:25:06 +0000
committerpixel <pixel>2007-06-11 21:25:06 +0000
commit3cbdf9478a18f21e28c3bc196fed72e26ca87168 (patch)
tree1c6eb59e8e020b7902a872cf3df1e49ccfa98df5
parentbf790985d8fff8389f278131b128eb65777d2c3a (diff)
Adding some more code to the supportlib.
-rw-r--r--lib/supportlib.lua31
1 files changed, 30 insertions, 1 deletions
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