Better names for variables
[prosody.git] / util / jid.lua
1
2 local match = string.match;
3
4 module "jid"
5
6 function split(jid)
7         if not jid then return; end
8         local node, nodepos = match(jid, "^([^@]+)@()");
9         local host, hostpos = match(jid, "^([^@/]+)()", nodepos)
10         if node and not host then return nil, nil, nil; end
11         local resource = match(jid, "^/(.+)$", hostpos);
12         if (not host) or ((not resource) and #jid >= hostpos) then return nil, nil, nil; end
13         return node, host, resource;
14 end
15
16 function bare(jid)
17         local node, host = split(jid);
18         if node and host then
19                 return node.."@"..host;
20         elseif host then
21                 return host;
22         end
23         return nil;
24 end
25
26 return _M;