Skip to content

Instantly share code, notes, and snippets.

@blt
Created April 25, 2011 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blt/940638 to your computer and use it in GitHub Desktop.
Save blt/940638 to your computer and use it in GitHub Desktop.
import scala.util.matching.Regex
object JID {
private val jidRe = new Regex("""(?i)(\w+)@([^/]+)/?+(.+)?+""")
def apply(parts: Seq[String]): String =
parts.size match {
case 2 => """%s@%s""".format(parts:_*)
case 3 => """%s@%s/%s""".format(parts:_*)
}
def unapplySeq(jid:String): Option[Seq[String]] =
jid match {
case jidRe(username,domain,resource) =>
if (resource == null)
Some( Seq(username,domain) )
else
Some( Seq(username,domain,resource) )
case _ => None
}
}
class JID(jid:String) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment