# HG changeset patch # User Waqas Hussain # Date 1320172892 -18000 # Node ID f78c6f5fa0903192a8016848701748f2a4b9db25 # Parent 424e14d3f99bd50627fcfe1226f8f73ee5ced6ef util.jid: Added escape() and unescape(). diff -r 424e14d3f99b -r f78c6f5fa090 util/jid.lua --- a/util/jid.lua Wed Oct 26 18:58:01 2011 -0400 +++ b/util/jid.lua Tue Nov 01 23:41:32 2011 +0500 @@ -13,6 +13,16 @@ local nameprep = require "util.encodings".stringprep.nameprep; local resourceprep = require "util.encodings".stringprep.resourceprep; +local escapes = { + [" "] = "\\20"; ['"'] = "\\22"; + ["&"] = "\\26"; ["'"] = "\\27"; + ["/"] = "\\2f"; [":"] = "\\3a"; + ["<"] = "\\3c"; [">"] = "\\3e"; + ["@"] = "\\40"; ["\\"] = "\\5c"; +}; +local unescapes = {}; +for k,v in pairs(escapes) do unescapes[v] = k; end + module "jid" local function _split(jid) @@ -91,4 +101,7 @@ return false end +function escape(s) return s and (s:gsub(".", escapes)); end +function unescape(s) return s and (s:gsub("\\%x%x", unescapes)); end + return _M;