src/Pure/General/xml_data.scala
changeset 38439 386fd5c0ccbf
parent 38355 8cb265fb12fe
child 43698 91c4d7397f0e
equal deleted inserted replaced
38438:9513c79ac4cc 38439:386fd5c0ccbf
    11 object XML_Data
    11 object XML_Data
    12 {
    12 {
    13   /* basic values */
    13   /* basic values */
    14 
    14 
    15   class XML_Atom(s: String) extends Exception(s)
    15   class XML_Atom(s: String) extends Exception(s)
       
    16 
       
    17 
       
    18   private def make_long_atom(i: Long): String = i.toString
       
    19 
       
    20   private def dest_long_atom(s: String): Long =
       
    21     try { java.lang.Long.parseLong(s) }
       
    22     catch { case e: NumberFormatException => throw new XML_Atom(s) }
    16 
    23 
    17 
    24 
    18   private def make_int_atom(i: Int): String = i.toString
    25   private def make_int_atom(i: Int): String = i.toString
    19 
    26 
    20   private def dest_int_atom(s: String): Int =
    27   private def dest_int_atom(s: String): Int =
    69       case List(XML.Text(s)) => s
    76       case List(XML.Text(s)) => s
    70       case _ => throw new XML_Body(ts)
    77       case _ => throw new XML_Body(ts)
    71     }
    78     }
    72 
    79 
    73 
    80 
       
    81   def make_long(i: Long): XML.Body = make_string(make_long_atom(i))
       
    82   def dest_long(ts: XML.Body): Long = dest_long_atom(dest_string(ts))
       
    83 
    74   def make_int(i: Int): XML.Body = make_string(make_int_atom(i))
    84   def make_int(i: Int): XML.Body = make_string(make_int_atom(i))
    75   def dest_int(ts: XML.Body): Int = dest_int_atom(dest_string(ts))
    85   def dest_int(ts: XML.Body): Int = dest_int_atom(dest_string(ts))
    76 
    86 
    77   def make_bool(b: Boolean): XML.Body = make_string(make_bool_atom(b))
    87   def make_bool(b: Boolean): XML.Body = make_string(make_bool_atom(b))
    78   def dest_bool(ts: XML.Body) = dest_bool_atom(dest_string(ts))
    88   def dest_bool(ts: XML.Body) = dest_bool_atom(dest_string(ts))