Software /
code /
prosody
Comparison
util/jid.lua @ 4407:f78c6f5fa090
util.jid: Added escape() and unescape().
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Tue, 01 Nov 2011 23:41:32 +0500 |
parent | 3480:97831dfe7f72 |
child | 5776:bd0ff8ae98a8 |
child | 5944:f3817912e8b2 |
comparison
equal
deleted
inserted
replaced
4406:424e14d3f99b | 4407:f78c6f5fa090 |
---|---|
10 | 10 |
11 local match = string.match; | 11 local match = string.match; |
12 local nodeprep = require "util.encodings".stringprep.nodeprep; | 12 local nodeprep = require "util.encodings".stringprep.nodeprep; |
13 local nameprep = require "util.encodings".stringprep.nameprep; | 13 local nameprep = require "util.encodings".stringprep.nameprep; |
14 local resourceprep = require "util.encodings".stringprep.resourceprep; | 14 local resourceprep = require "util.encodings".stringprep.resourceprep; |
15 | |
16 local escapes = { | |
17 [" "] = "\\20"; ['"'] = "\\22"; | |
18 ["&"] = "\\26"; ["'"] = "\\27"; | |
19 ["/"] = "\\2f"; [":"] = "\\3a"; | |
20 ["<"] = "\\3c"; [">"] = "\\3e"; | |
21 ["@"] = "\\40"; ["\\"] = "\\5c"; | |
22 }; | |
23 local unescapes = {}; | |
24 for k,v in pairs(escapes) do unescapes[v] = k; end | |
15 | 25 |
16 module "jid" | 26 module "jid" |
17 | 27 |
18 local function _split(jid) | 28 local function _split(jid) |
19 if not jid then return; end | 29 if not jid then return; end |
89 return true | 99 return true |
90 end | 100 end |
91 return false | 101 return false |
92 end | 102 end |
93 | 103 |
104 function escape(s) return s and (s:gsub(".", escapes)); end | |
105 function unescape(s) return s and (s:gsub("\\%x%x", unescapes)); end | |
106 | |
94 return _M; | 107 return _M; |