Comparison

util/jid.lua @ 1171:be11dc0610d5

util.jid: Eliminate global method use
author Waqas Hussain <waqas20@gmail.com>
date Sat, 16 May 2009 03:56:51 +0500
parent 896:2c0b9e3c11c3
child 1523:841d61be198f
comparison
equal deleted inserted replaced
1170:4845372a2c03 1171:be11dc0610d5
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 15
16 module "jid" 16 module "jid"
17 17
18 function split(jid) 18 local function _split(jid)
19 if not jid then return; end 19 if not jid then return; end
20 local node, nodepos = match(jid, "^([^@]+)@()"); 20 local node, nodepos = match(jid, "^([^@]+)@()");
21 local host, hostpos = match(jid, "^([^@/]+)()", nodepos) 21 local host, hostpos = match(jid, "^([^@/]+)()", nodepos)
22 if node and not host then return nil, nil, nil; end 22 if node and not host then return nil, nil, nil; end
23 local resource = match(jid, "^/(.+)$", hostpos); 23 local resource = match(jid, "^/(.+)$", hostpos);
24 if (not host) or ((not resource) and #jid >= hostpos) then return nil, nil, nil; end 24 if (not host) or ((not resource) and #jid >= hostpos) then return nil, nil, nil; end
25 return node, host, resource; 25 return node, host, resource;
26 end 26 end
27 split = _split;
27 28
28 function bare(jid) 29 function bare(jid)
29 local node, host = split(jid); 30 local node, host = _split(jid);
30 if node and host then 31 if node and host then
31 return node.."@"..host; 32 return node.."@"..host;
32 end 33 end
33 return host; 34 return host;
34 end 35 end
35 36
36 function prepped_split(jid) 37 local function _prepped_split(jid)
37 local node, host, resource = split(jid); 38 local node, host, resource = _split(jid);
38 if host then 39 if host then
39 host = nameprep(host); 40 host = nameprep(host);
40 if not host then return; end 41 if not host then return; end
41 if node then 42 if node then
42 node = nodeprep(node); 43 node = nodeprep(node);
47 if not resource then return; end 48 if not resource then return; end
48 end 49 end
49 return node, host, resource; 50 return node, host, resource;
50 end 51 end
51 end 52 end
53 prepped_split = _prepped_split;
52 54
53 function prep(jid) 55 function prep(jid)
54 local node, host, resource = prepped_split(jid); 56 local node, host, resource = _prepped_split(jid);
55 if host then 57 if host then
56 if node then 58 if node then
57 host = node .. "@" .. host; 59 host = node .. "@" .. host;
58 end 60 end
59 if resource then 61 if resource then