# HG changeset patch # User Waqas Hussain <waqas20@gmail.com> # Date 1231976095 -18000 # Node ID ab428c579cbc5e21711c3202aac01ec47b1a64b0 # Parent d61eabc678a66f5c66d99f4c3aaa0aad1b9d1b72 util/jid: string prepping functions added: prepped_split and prep diff -r d61eabc678a6 -r ab428c579cbc util/jid.lua --- a/util/jid.lua Wed Jan 14 23:04:16 2009 +0500 +++ b/util/jid.lua Thu Jan 15 04:34:55 2009 +0500 @@ -20,6 +20,9 @@ local match = string.match; +local nodeprep = require "util.encodings".stringprep.nodeprep; +local nameprep = require "util.encodings".stringprep.nameprep; +local resourceprep = require "util.encodings".stringprep.resourceprep; module "jid" @@ -41,4 +44,34 @@ return host; end +function prepped_split(jid) + local node, host, resource = split(jid); + if host then + host = nameprep(host); + if not host then return; end + if node then + node = nodeprep(node); + if not node then return; end + end + if resource then + resource = resourceprep(resource); + if not resource then return; end + end + return node, host, resource; + end +end + +function prep(jid) + local node, host, resource = prepped_split(jid); + if host then + if node then + host = node .. "@" .. host; + end + if resource then + host = host .. "/" .. resource; + end + end + return host; +end + return _M;