src/Pure/General/uuid.scala
author wenzelm
Tue, 09 Jan 2024 23:41:50 +0100
changeset 79458 ca2fe94e8048
parent 77556 911548e4f228
child 79717 da4e82434985
permissions -rw-r--r--
tuned whitespace;

/*  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 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)))
}