src/Pure/General/uuid.scala
author wenzelm
Sat, 24 Feb 2024 11:05:11 +0100
changeset 79717 da4e82434985
parent 77556 911548e4f228
permissions -rw-r--r--
tuned signature;

/*  Title:      Pure/General/uuid.scala
    Author:     Makarius

Universally Unique Identifiers.
*/

package isabelle


object UUID {
  type T = java.util.UUID

  def random(): T = java.util.UUID.randomUUID()
  def random_string(): String = random().toString

  def unapply(s: String): Option[T] =
    try { Some(java.util.UUID.fromString(s)) }
    catch { case _: IllegalArgumentException => None }

  def unapply(body: XML.Body): Option[T] = unapply(XML.content(body))

  def make(s: String): T =
    unapply(s).getOrElse(error("Bad UUID: " + quote(s)))
}