From 3af54d9302cae389beec6c3ce3270f3b783d2fbd Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 17 Mar 2016 23:15:08 +0000 Subject: util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID --- util/jid.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'util') diff --git a/util/jid.lua b/util/jid.lua index 76155ac7..60bb0829 100644 --- a/util/jid.lua +++ b/util/jid.lua @@ -93,6 +93,18 @@ local function compare(jid, acl) return false end +local function node(jid) + return (select(1, split(jid))); +end + +local function host(jid) + return (select(2, split(jid))); +end + +local function resource(jid) + return (select(3, split(jid))); +end + local function escape(s) return s and (s:gsub(".", escapes)); end local function unescape(s) return s and (s:gsub("\\%x%x", unescapes)); end @@ -103,6 +115,9 @@ return { join = join; prep = prep; compare = compare; + node = node; + host = host; + resource = resource; escape = escape; unescape = unescape; }; -- cgit v1.2.3