util/jid.lua
author Matthew Wild <mwild1@gmail.com>
Thu, 20 Nov 2008 23:28:16 +0000
changeset 365 a59300fc22ec
parent 109 7efedc96352a
child 366 5691edc7dd63
permissions -rw-r--r--
Add jid.bare() helper function


local match = string.match;

module "jid"

function split(jid)
	if not jid then return; end
	-- TODO verify JID, and return; if invalid
	local node = match(jid, "^([^@]+)@");
	local server = (node and match(jid, ".-@([^@/]+)")) or match(jid, "^([^@/]+)");
	local resource = match(jid, "/(.+)$");
	return node, server, resource;
end

function bare(jid)
	local node, host = split(jid);
	return node.."@"..host;
end

return _M;