changeset 464:d7b0ddec1929

URL encode/decode helpers.
author Aleksandr Rybalko <ray@ddteam.net>
date Mon, 24 Sep 2012 14:14:50 +0300
parents 24007794e57a
children b61a12ee8443
files profiles/lua_web_ui/files/etc/www/lib/urlXxcode.lua
diffstat 1 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/profiles/lua_web_ui/files/etc/www/lib/urlXxcode.lua	Mon Sep 24 14:14:50 2012 +0300
@@ -0,0 +1,22 @@
+--
+-- Utility function:  URL encoding function
+--
+function urlEncode(str)
+    if (str) then
+        str = string.gsub (str, "\n", "\r\n")
+        str = string.gsub (str, "([^%w ])",
+            function (c) return string.format ("%%%02X", string.byte(c)) end)
+        str = string.gsub (str, " ", "+")
+    end
+    return str
+end
+
+--
+-- Utility function:  URL decode function
+--
+function urlDecode(str)
+    str = string.gsub (str, "+", " ")
+    str = string.gsub (str, "%%(%x%x)", function(h) return string.char(tonumber(h,16)) end)
+    str = string.gsub (str, "\r\n", "\n")
+    return str
+end