summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2004-02-11 18:40:47 +0000
committerburaq <buraq@epfl.ch>2004-02-11 18:40:47 +0000
commitdd760546570fc0ecca90ea3b417078d8509c4042 (patch)
tree57460e6248514e252190def84b9340b9034c1ae1
parenta10fed035d6aa6544bad270163891594d3a577ea (diff)
downloadscala-dd760546570fc0ecca90ea3b417078d8509c4042.tar.gz
scala-dd760546570fc0ecca90ea3b417078d8509c4042.tar.bz2
scala-dd760546570fc0ecca90ea3b417078d8509c4042.zip
started pretty print functions
-rw-r--r--sources/scala/xml/Utility.scala57
1 files changed, 51 insertions, 6 deletions
diff --git a/sources/scala/xml/Utility.scala b/sources/scala/xml/Utility.scala
index 985f7fd3c1..fd9eda8e5d 100644
--- a/sources/scala/xml/Utility.scala
+++ b/sources/scala/xml/Utility.scala
@@ -34,23 +34,68 @@ object Utility {
}
/** serializes an instance of Node to a string that contains well-formed XML **/
- def toXML( n:Node ):String = { n match {
+ def toXML( n:Node ):String = n match {
case Text( t ) =>
escape( t );
- case x:AttributedNode =>
+ case x:AttributedNode => {
val s = new StringBuffer();
- s.append("<");
+ s.append('<');
s.append( x.label );
if( null != x.attributes ) {
s.append( attr2xml( x.attributes.elements ) );{}
}
- s.append(">");
- s.append( toXML( x.children.elements ) );
+ s.append('>');
+ s.append( toXML( x.children.elements ) );
s.append("</");
s.append( x.label );
- s.append(">");
+ s.append('>');
s.toString()
+ }
+ }
+
+ /** serializes an instance of Node to a string that contains well-formed XML **/
+/*
+ def toPrettyXML( n:Node, indent:int ):String = { n match {
+ case Text( t ) =>
+ escape( t );
+ case x:AttributedNode =>
+ val s = new StringBuffer();
+ for( val i<-List.range(0,indent) ) {
+ val _ = s.append(" ");
+ {}
+ }
+ val spaces = s.toString();
+ s.append('<');
+ s.append( x.label );
+ if( null != x.attributes ) {
+ s.append( attr2xml( x.attributes.elements ) );{}
+ }
+ s.append('>');
+ val childrenString = toXML( x.children.elements, 0 );
+ if( indent + 2 * x.label.length() + 4 + childrenString.length() < COLS ) {
+ s.append( childrenString );
+ s.append("</");
+ s.append( x.label );
+ s.append('>');
+ s.append('\n');
+ } else {
+ s.append('\n');
+ val childrenString = toXML( x.children.elements, indent+1 ) ;
+ s.append( childrenString );
+ s.append('\n');
+ s.append( spaces );
+ s.append("</");
+ s.append( x.label );
+ s.append('>');
+ }
+ s.toString()
}}
+ def toXML( ch:Iterator[Node], ind:int ):String = {
+ ch.foldLeft ("") { (s:String,n:Node) => {
+ val t:String = toPrettyXML( n, ind ); s + t
+ }}
+ }
+todo: better pretty printing */
def toXML( ch:Iterator[Node] ):String = {
ch.foldLeft ("") { (s:String,n:Node) => { val t:String = toXML( n ); s + t }}