From: Mickael Remond Date: Tue, 4 Aug 2015 07:48:59 +0000 (+0200) Subject: Add split_jid/1 X-Git-Tag: 15.09~93 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e3b7d43b76ecbca7c56f2e85c83fa6eaf5de6538;p=ejabberd Add split_jid/1 This is a convenience reverse of make_jid/1. It allows extracting the jid parts without relying on using the jid record structure, to abstract details. --- diff --git a/src/jlib.erl b/src/jlib.erl index 389783b24..cc0f826ab 100644 --- a/src/jlib.erl +++ b/src/jlib.erl @@ -39,7 +39,7 @@ make_error_reply/2, make_error_element/2, make_correct_from_to_attrs/3, replace_from_to_attrs/3, replace_from_to/3, replace_from_attrs/2, replace_from/2, - remove_attr/2, make_jid/3, make_jid/1, string_to_jid/1, + remove_attr/2, make_jid/3, make_jid/1, split_jid/1, string_to_jid/1, jid_to_string/1, is_nodename/1, tolower/1, nodeprep/1, nameprep/1, resourceprep/1, jid_tolower/1, jid_remove_resource/1, jid_replace_resource/2, @@ -214,6 +214,13 @@ make_jid(User, Server, Resource) -> make_jid({User, Server, Resource}) -> make_jid(User, Server, Resource). +%% This is the reverse of make_jid/1 +-spec split_jid(jid()) -> {binary(), binary(), binary()} | error. +split_jid(#jid{user = U, server = S, resource = R}) -> + {U, S, R}; +split_jid(_) -> + error. + -spec string_to_jid(binary()) -> jid() | error. string_to_jid(S) ->