summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBurak Emir <emir@epfl.ch>2006-03-14 16:17:17 +0000
committerBurak Emir <emir@epfl.ch>2006-03-14 16:17:17 +0000
commit7ede3d70d261e4905523f174d73f25b3b1476082 (patch)
tree46fbfcfdba4604580a77dd622054eb95a1a1e08e /src
parent496ed79cbb1752f3b57a1057b3c8e8873f1784c0 (diff)
downloadscala-7ede3d70d261e4905523f174d73f25b3b1476082.tar.gz
scala-7ede3d70d261e4905523f174d73f25b3b1476082.tar.bz2
scala-7ede3d70d261e4905523f174d73f25b3b1476082.zip
prtty printer update plus node::\ method
Diffstat (limited to 'src')
-rw-r--r--src/library/scala/xml/Node.scala2
-rw-r--r--src/library/scala/xml/PrettyPrinter.scala16
2 files changed, 12 insertions, 6 deletions
diff --git a/src/library/scala/xml/Node.scala b/src/library/scala/xml/Node.scala
index e02b47886d..96eb3db408 100644
--- a/src/library/scala/xml/Node.scala
+++ b/src/library/scala/xml/Node.scala
@@ -83,7 +83,7 @@ abstract class Node extends NodeSeq {
/** descendant axis (all descendants of this node, not including not itself) */
def descendant: List[Node] =
- child.toList.flatMap { x => x::x.descendant } ;
+ child.toList.flatMap { x => if(x.typeTag$ != -1) x::x.descendant else Nil } ;
/** descendant axis (all descendants of this node, including this node) */
def descendant_or_self: List[Node] = this :: descendant;
diff --git a/src/library/scala/xml/PrettyPrinter.scala b/src/library/scala/xml/PrettyPrinter.scala
index e51c5efe7a..c612edd2e7 100644
--- a/src/library/scala/xml/PrettyPrinter.scala
+++ b/src/library/scala/xml/PrettyPrinter.scala
@@ -53,7 +53,7 @@ class PrettyPrinter( width:Int, step:Int ) {
var i = s.indexOf(' ');
if(i > tmp || i == -1) throw new BrokenException(); // cannot break
- var last:List[Int] = i::Nil;
+ var last:List[Int] = Nil;
while(i < tmp) {
last = i::last;
i = s.indexOf(' ', i );
@@ -144,11 +144,14 @@ class PrettyPrinter( width:Int, step:Int ) {
/** @param tail: what we'd like to sqeeze in */
protected def traverse(node: Node, pscope: NamespaceBinding, ind: Int): Unit = node match {
+ case Text(s) if s.trim() == "" =>
+
case _:Atom[Any] | _:Molecule[Any] | _:Comment | _:EntityRef | _:ProcInstr =>
- makeBox( ind, node.toString() );
+ makeBox( ind, node.toString().trim() );
case _:Node =>
- val test = { val sb = new StringBuffer(); Utility.toXML(node, pscope, sb, false); sb.toString()};
+ val test = { val sb = new StringBuffer(); Utility.toXML(node, pscope, sb, false);
+ val tb = TextBuffer.fromString(sb.toString()); tb.toText(0)._data};
if(childrenAreLeaves(node) && fits(test)) {
makeBox( ind, test );
} else {
@@ -203,13 +206,14 @@ class PrettyPrinter( width:Int, step:Int ) {
}
def format(n: Node, pscope:NamespaceBinding, sb: StringBuffer): Unit = { // entry point
+ var lastwasbreak = false;
reset();
traverse( n, pscope, 0 );
var cur = 0;
- //Console.println( items.reverse );
for( val b <- items.reverse ) b match {
case Break =>
- sb.append('\n'); // on windows: \r\n ?
+ if(!lastwasbreak) sb.append('\n'); // on windows: \r\n ?
+ lastwasbreak = true
cur = 0;
// while( cur < last ) {
// sb.append(' ');
@@ -217,12 +221,14 @@ class PrettyPrinter( width:Int, step:Int ) {
// }
case Box(i, s) =>
+ lastwasbreak = false
while( cur < i ) {
sb.append(' ');
cur = cur + 1;
}
sb.append( s );
case Para( s ) =>
+ lastwasbreak = false
sb.append( s );
}
}