src/Pure/PIDE/xml.scala
changeset 73202 8a17c7bf530a
parent 73032 72b13af7f266
child 73203 9c10b4fa17b5
equal deleted inserted replaced
73201:b80029a40ccf 73202:8a17c7bf530a
   126 
   126 
   127   /** string representation **/
   127   /** string representation **/
   128 
   128 
   129   val header: String = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
   129   val header: String = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
   130 
   130 
   131   def output_char(c: Char, s: StringBuilder)
   131   def output_char(s: StringBuilder, c: Char)
   132   {
   132   {
   133     c match {
   133     c match {
   134       case '<' => s ++= "&lt;"
   134       case '<' => s ++= "&lt;"
   135       case '>' => s ++= "&gt;"
   135       case '>' => s ++= "&gt;"
   136       case '&' => s ++= "&amp;"
   136       case '&' => s ++= "&amp;"
   138       case '\'' => s ++= "&apos;"
   138       case '\'' => s ++= "&apos;"
   139       case _ => s += c
   139       case _ => s += c
   140     }
   140     }
   141   }
   141   }
   142 
   142 
   143   def output_string(str: String, s: StringBuilder)
   143   def output_string(s: StringBuilder, str: String)
   144   {
   144   {
   145     if (str == null) s ++= str
   145     if (str == null) s ++= str
   146     else str.iterator.foreach(c => output_char(c, s))
   146     else str.iterator.foreach(c => output_char(s, c))
   147   }
   147   }
   148 
   148 
   149   def string_of_body(body: Body): String =
   149   def string_of_body(body: Body): String =
   150   {
   150   {
   151     val s = new StringBuilder
   151     val s = new StringBuilder
   152 
   152 
   153     def text(txt: String) { output_string(txt, s) }
   153     def text(txt: String) { output_string(s, txt) }
   154     def elem(markup: Markup)
   154     def elem(markup: Markup)
   155     {
   155     {
   156       s ++= markup.name
   156       s ++= markup.name
   157       for ((a, b) <- markup.properties) {
   157       for ((a, b) <- markup.properties) {
   158         s += ' '; s ++= a; s += '='; s += '"'; text(b); s += '"'
   158         s += ' '; s ++= a; s += '='; s += '"'; text(b); s += '"'