summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2004-06-02 09:31:01 +0000
committerburaq <buraq@epfl.ch>2004-06-02 09:31:01 +0000
commit18d6311803a8755273e8bfc603fa8b6080c647da (patch)
tree0f97a5ca6923406208f7c191df9c505d8c1e7627 /sources
parent6af09c2f220de5012bf4b6683286aa4e0fba1170 (diff)
downloadscala-18d6311803a8755273e8bfc603fa8b6080c647da.tar.gz
scala-18d6311803a8755273e8bfc603fa8b6080c647da.tar.bz2
scala-18d6311803a8755273e8bfc603fa8b6080c647da.zip
comment
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/xml/PrettyPrinter.scala28
1 files changed, 17 insertions, 11 deletions
diff --git a/sources/scala/xml/PrettyPrinter.scala b/sources/scala/xml/PrettyPrinter.scala
index 13e4b4570b..e62139b3aa 100644
--- a/sources/scala/xml/PrettyPrinter.scala
+++ b/sources/scala/xml/PrettyPrinter.scala
@@ -12,8 +12,12 @@ package scala.xml ;
import java.lang.StringBuffer ; /* Java dependency! */
import scala.collection.Map ;
-/** Utility functions for processing instances of bound and not bound XML
-** classes, as well as escaping text nodes
+/** Class for pretty printing. After instantiating, you can use the
+ * toPrettyXML methods to convert XML to a formatted string. The class
+ * can be reused to pretty print any number of XML nodes.
+ *
+ * @param width the width to fit the output into
+ * @step indentation
**/
class PrettyPrinter( width:Int, step:Int ) {
@@ -36,7 +40,7 @@ class PrettyPrinter( width:Int, step:Int ) {
items = Nil;
}
- /** try to cut at whitespace */
+ /* try to cut at whitespace */
def cut( s:String, ind:Int ):List[Item] = {
val tmp = width - cur;
if( s.length() < tmp )
@@ -105,7 +109,7 @@ class PrettyPrinter( width:Int, step:Int ) {
sb.toString();
}
- /* serializes an instance of Node to a string that contains well-formed XML
+ /* returns a formatted string containing well-formed XML
**/
def toPrettyXML( n:Node ):String = {
reset();
@@ -129,13 +133,15 @@ class PrettyPrinter( width:Int, step:Int ) {
sb.toString();
}
-// def toLastWS( len:Int, s:String ) = {
-// val sb = new StringBuffer();
-// while( len
-// attr2xml( attribute.elements, sb );
-// sb.append('>');
-// sb.toString();
-// }
+ /* returns a formatted string containing well-formed XML nodes.
+ **/
+ def toPrettyXML( ns:Seq[Node] ):String = {
+ var sb2 = new StringBuffer();
+ for( val n <- ns.elements ) {
+ sb2.append( toPrettyXML( n ))
+ }
+ sb2.toString();
+ }
def breakable( n:Node ):boolean = {
val it = n.child.elements;