# HG changeset patch # User wenzelm # Date 1289058787 -3600 # Node ID 6f47c49fed845fe31fa29d73afcd3e2d96c8544d # Parent b0dafbfc05b7e18be9a2bcb979ae506bf676e443 added Markup.Double, Markup.Double_Property; tuned; diff -r b0dafbfc05b7 -r 6f47c49fed84 src/Pure/General/markup.scala --- a/src/Pure/General/markup.scala Sat Nov 06 16:31:35 2010 +0100 +++ b/src/Pure/General/markup.scala Sat Nov 06 16:53:07 2010 +0100 @@ -11,20 +11,30 @@ { /* plain values */ - object Int { - def apply(i: scala.Int): String = i.toString + object Int + { + def apply(x: scala.Int): String = x.toString def unapply(s: String): Option[scala.Int] = try { Some(Integer.parseInt(s)) } catch { case _: NumberFormatException => None } } - object Long { - def apply(i: scala.Long): String = i.toString + object Long + { + def apply(x: scala.Long): String = x.toString def unapply(s: String): Option[scala.Long] = try { Some(java.lang.Long.parseLong(s)) } catch { case _: NumberFormatException => None } } + object Double + { + def apply(x: scala.Double): String = x.toString + def unapply(s: String): Option[scala.Double] = + try { Some(java.lang.Double.parseDouble(s)) } + catch { case _: NumberFormatException => None } + } + /* named properties */ @@ -55,6 +65,16 @@ } } + class Double_Property(name: String) + { + def apply(value: scala.Double): List[(String, String)] = List((name, Double(value))) + def unapply(props: List[(String, String)]): Option[Double] = + props.find(_._1 == name) match { + case None => None + case Some((_, value)) => Double.unapply(value) + } + } + /* empty */