summaryrefslogtreecommitdiff
path: root/src/library/scala/text/Document.scala
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2006-09-20 16:03:18 +0000
committermichelou <michelou@epfl.ch>2006-09-20 16:03:18 +0000
commitbc14c4aa87d8df3569785fa77fe67693c57cf6c7 (patch)
treeb7dc73f9dea3fc26ffc3ba68676c2fdbb1c5e940 /src/library/scala/text/Document.scala
parent54a8dae948be3ced9f1e1f338b38910c6df4da69 (diff)
downloadscala-bc14c4aa87d8df3569785fa77fe67693c57cf6c7.tar.gz
scala-bc14c4aa87d8df3569785fa77fe67693c57cf6c7.tar.bz2
scala-bc14c4aa87d8df3569785fa77fe67693c57cf6c7.zip
removed leading/trailing tabs/blanks in scala/u...
removed leading/trailing tabs/blanks in scala/util/*.scala
Diffstat (limited to 'src/library/scala/text/Document.scala')
-rw-r--r--src/library/scala/text/Document.scala61
1 files changed, 32 insertions, 29 deletions
diff --git a/src/library/scala/text/Document.scala b/src/library/scala/text/Document.scala
index f5059862dd..70e7bc8fc7 100644
--- a/src/library/scala/text/Document.scala
+++ b/src/library/scala/text/Document.scala
@@ -9,17 +9,17 @@
// $Id$
-package scala.text;
+package scala.text
-import java.io.Writer;
+import java.io.Writer
-case object DocNil extends Document;
-case object DocBreak extends Document;
-case class DocText(txt: String) extends Document;
-case class DocGroup(doc: Document) extends Document;
-case class DocNest(indent: Int, doc: Document) extends Document;
-case class DocCons(hd: Document, tl: Document) extends Document;
+case object DocNil extends Document
+case object DocBreak extends Document
+case class DocText(txt: String) extends Document
+case class DocGroup(doc: Document) extends Document
+case class DocNest(indent: Int, doc: Document) extends Document
+case class DocCons(hd: Document, tl: Document) extends Document
/**
* A basic pretty-printing library, based on Lindig's strict version
@@ -30,17 +30,20 @@ case class DocCons(hd: Document, tl: Document) extends Document;
*/
abstract class Document {
- def ::(hd: Document): Document = DocCons(hd, this);
- def ::(hd: String): Document = DocCons(DocText(hd), this);
- def :/:(hd: Document): Document = hd :: DocBreak :: this;
- def :/:(hd: String): Document = hd :: DocBreak :: this;
+ def ::(hd: Document): Document = DocCons(hd, this)
+ def ::(hd: String): Document = DocCons(DocText(hd), this)
+ def :/:(hd: Document): Document = hd :: DocBreak :: this
+ def :/:(hd: String): Document = hd :: DocBreak :: this
/**
* Format this document on WRITER and try to set line breaks so that
* the result fits in WIDTH columns.
+ *
+ * @param width ...
+ * @param writer ...
*/
def format(width: Int, writer: Writer): Unit = {
- type FmtState = Triple[Int,Boolean,Document];
+ type FmtState = Triple[Int,Boolean,Document]
def fits(w: Int, state: List[FmtState]): boolean = state match {
case _ if w < 0 =>
@@ -64,12 +67,12 @@ abstract class Document {
}
def spaces(n: Int): Unit = {
- var rem = n;
- while (rem >= 16) { writer write " "; rem = rem - 16 };
- if (rem >= 8) { writer write " "; rem = rem - 8 };
- if (rem >= 4) { writer write " "; rem = rem - 4 };
- if (rem >= 2) { writer write " "; rem = rem - 2};
- if (rem == 1) { writer write " " };
+ var rem = n
+ while (rem >= 16) { writer write " "; rem = rem - 16 }
+ if (rem >= 8) { writer write " "; rem = rem - 8 }
+ if (rem >= 4) { writer write " "; rem = rem - 4 }
+ if (rem >= 2) { writer write " "; rem = rem - 2}
+ if (rem == 1) { writer write " " }
}
def fmt(k: Int, state: List[FmtState]): Unit = state match {
@@ -79,42 +82,42 @@ abstract class Document {
case Triple(i, b, DocCons(h, t)) :: z =>
fmt(k, Triple(i, b, h) :: Triple(i, b, t) :: z)
case Triple(i, _, DocText(t)) :: z =>
- writer write t;
+ writer write t
fmt(k + t.length(), z)
case Triple(i, b, DocNest(ii, d)) :: z =>
fmt(k, Triple(i + ii, b, d) :: z)
case Triple(i, true, DocBreak) :: z =>
- writer write "\n";
+ writer write "\n"
spaces(i);
fmt(i, z)
case Triple(i, false, DocBreak) :: z =>
- writer write " ";
+ writer write " "
fmt(k + 1, z)
case Triple(i, b, DocGroup(d)) :: z =>
- val fitsFlat = fits(width - k, Triple(i, false, d) :: z);
+ val fitsFlat = fits(width - k, Triple(i, false, d) :: z)
fmt(k, Triple(i, !fitsFlat, d) :: z)
}
- fmt(0, Triple(0, false, DocGroup(this)) :: Nil);
+ fmt(0, Triple(0, false, DocGroup(this)) :: Nil)
}
}
object Document {
/** The empty document */
- def empty = DocNil;
+ def empty = DocNil
/** A break, which will either be turned into a space or a line break */
- def break = DocBreak;
+ def break = DocBreak
/** A document consisting of some text literal */
- def text(s: String): Document = DocText(s);
+ def text(s: String): Document = DocText(s)
/**
* A group, whose components will either be printed with all breaks
* rendered as spaces, or with all breaks rendered as line breaks.
*/
- def group(d: Document): Document = DocGroup(d);
+ def group(d: Document): Document = DocGroup(d)
/** A nested document, which will be indented as specified. */
- def nest(i: Int, d: Document): Document = DocNest(i, d);
+ def nest(i: Int, d: Document): Document = DocNest(i, d)
}