Created
April 25, 2011 15:06
-
-
Save blt/940638 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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