static Symbol.spaces;
authorwenzelm
Sun, 09 May 2010 13:12:22 +0200
changeset 36763 096ebe74aeaf
parent 36762 40837a7b32a7
child 36764 17427cf6fe95
static Symbol.spaces;
src/Pure/General/pretty.scala
src/Pure/General/symbol.scala
--- a/src/Pure/General/pretty.scala	Sat May 08 21:25:25 2010 +0200
+++ b/src/Pure/General/pretty.scala	Sun May 09 13:12:22 2010 +0200
@@ -30,7 +30,8 @@
   object Break
   {
     def apply(width: Int): XML.Tree =
-      XML.Elem(Markup.BREAK, List((Markup.WIDTH, width.toString)), List(XML.Text(" " * width)))
+      XML.Elem(Markup.BREAK, List((Markup.WIDTH, width.toString)),
+        List(XML.Text(Symbol.spaces(width))))
 
     def unapply(tree: XML.Tree): Option[Int] =
       tree match {
@@ -48,7 +49,7 @@
   {
     def newline: Text = copy(tx = FBreak :: tx, pos = 0, nl = nl + 1)
     def string(s: String): Text = copy(tx = XML.Text(s) :: tx, pos = pos + s.length)
-    def blanks(wd: Int): Text = string(" " * wd)
+    def blanks(wd: Int): Text = string(Symbol.spaces(wd))
     def content: List[XML.Tree] = tx.reverse
   }
 
@@ -126,7 +127,7 @@
     def fmt(tree: XML.Tree): List[XML.Tree] =
       tree match {
         case Block(_, body) => body.flatMap(fmt)
-        case Break(wd) => List(XML.Text(" " * wd))
+        case Break(wd) => List(XML.Text(Symbol.spaces(wd)))
         case FBreak => List(XML.Text(" "))
         case XML.Elem(name, atts, body) => List(XML.Elem(name, atts, body.flatMap(fmt)))
         case XML.Text(_) => List(tree)
--- a/src/Pure/General/symbol.scala	Sat May 08 21:25:25 2010 +0200
+++ b/src/Pure/General/symbol.scala	Sun May 09 13:12:22 2010 +0200
@@ -13,6 +13,18 @@
 
 object Symbol
 {
+  /* spaces */
+
+  private val static_spaces = " " * 4000
+
+  def spaces(k: Int): String =
+  {
+    require(k >= 0)
+    if (k < static_spaces.length) static_spaces.substring(0, k)
+    else " " * k
+  }
+
+
   /* Symbol regexps */
 
   private val plain = new Regex("""(?xs)