diff options
author | Burak Emir <emir@epfl.ch> | 2005-11-04 02:42:29 +0000 |
---|---|---|
committer | Burak Emir <emir@epfl.ch> | 2005-11-04 02:42:29 +0000 |
commit | 2f369fd34865da083e0e6b5c049334fae89aeb6c (patch) | |
tree | 32edefb545dbef8b2dfebbf269437d7abd3bf144 /sources | |
parent | 387dd38c1ed225aefa30720bc43d39b3e4ea80ad (diff) | |
download | scala-2f369fd34865da083e0e6b5c049334fae89aeb6c.tar.gz scala-2f369fd34865da083e0e6b5c049334fae89aeb6c.tar.bz2 scala-2f369fd34865da083e0e6b5c049334fae89aeb6c.zip |
added 'text' method
Diffstat (limited to 'sources')
-rw-r--r-- | sources/scala/xml/Atom.scala | 2 | ||||
-rw-r--r-- | sources/scala/xml/Comment.scala | 12 | ||||
-rw-r--r-- | sources/scala/xml/Elem.scala | 9 | ||||
-rw-r--r-- | sources/scala/xml/Node.scala | 2 | ||||
-rw-r--r-- | sources/scala/xml/NodeSeq.scala | 13 | ||||
-rw-r--r-- | sources/scala/xml/ProcInstr.scala | 13 | ||||
-rw-r--r-- | sources/scala/xml/Text.scala | 4 |
7 files changed, 40 insertions, 15 deletions
diff --git a/sources/scala/xml/Atom.scala b/sources/scala/xml/Atom.scala index 37548a9ef3..d37d6dbf56 100644 --- a/sources/scala/xml/Atom.scala +++ b/sources/scala/xml/Atom.scala @@ -36,4 +36,6 @@ class Atom[+A]( val data: A ) extends SpecialNode { def toString(sb:StringBuffer) = Utility.escape( data.toString(), sb ); + override def text: String = data.toString(); + } diff --git a/sources/scala/xml/Comment.scala b/sources/scala/xml/Comment.scala index d075fdad77..4bf7a267f7 100644 --- a/sources/scala/xml/Comment.scala +++ b/sources/scala/xml/Comment.scala @@ -17,16 +17,16 @@ import scala.collection.immutable ; * @param text text contained in this node, may not contain "--" */ -case class Comment(text: String) extends SpecialNode { +case class Comment(commentText: String) extends SpecialNode { final override def typeTag$:Int = -3; - if( text.indexOf("--" ) != -1 ) + if( commentText.indexOf("--" ) != -1 ) throw new IllegalArgumentException("text containts \"--\""); /** structural equality */ override def equals(x: Any): Boolean = x match { - case Comment(x) => x.equals(text); + case Comment(x) => x.equals(commentText); case _ => false } @@ -34,10 +34,12 @@ case class Comment(text: String) extends SpecialNode { def label = "#REM"; /** hashcode for this Comment */ - override def hashCode() = text.hashCode(); + override def hashCode() = commentText.hashCode(); + + override def text = ""; /** appends "<!-- text -->" to this stringbuffer */ def toString(sb: StringBuffer) = { - sb.append("<!--").append(text).append("-->") + sb.append("<!--").append(commentText).append("-->") } } diff --git a/sources/scala/xml/Elem.scala b/sources/scala/xml/Elem.scala index bb799884bb..ebf6a39cbe 100644 --- a/sources/scala/xml/Elem.scala +++ b/sources/scala/xml/Elem.scala @@ -58,4 +58,13 @@ case class Elem(override val prefix: String, scope, child:_*); + override def text = { + val sb = new StringBuffer(); + val it = child.elements; + while(it.hasNext) { + sb.append(it.next); + } + sb.toString() + } + } diff --git a/sources/scala/xml/Node.scala b/sources/scala/xml/Node.scala index 6f1a5de3b8..1aea168ff6 100644 --- a/sources/scala/xml/Node.scala +++ b/sources/scala/xml/Node.scala @@ -121,4 +121,6 @@ abstract class Node extends NodeSeq { /** returns a type symbol (e.g. DTD, XSD), default null */ def xmlType(): TypeSymbol = null; + override def text: String; + } diff --git a/sources/scala/xml/NodeSeq.scala b/sources/scala/xml/NodeSeq.scala index c463c88df5..b03fb0f3e4 100644 --- a/sources/scala/xml/NodeSeq.scala +++ b/sources/scala/xml/NodeSeq.scala @@ -23,12 +23,15 @@ abstract class NodeSeq extends Seq[Node] { def theSeq: Seq[Node]; def length = theSeq.length; def elements = theSeq.elements ; - def apply( i:int ) = theSeq.apply( i ); + def apply(i: int ): Node = theSeq.apply( i ); + + def apply(f: Node => Boolean): NodeSeq = filter(f); /** structural equality */ override def equals( x:Any ) = x match { case z:Node => ( length == 1 ) && z == apply( 0 ) case z:Seq[Node] => sameElements( z ) + case z:String => text == z case _ => false; } @@ -91,4 +94,12 @@ abstract class NodeSeq extends Seq[Node] { def filter(f:Node => Boolean): NodeSeq = { val x = asList filter f; x } + def text: String = { + val sb = new StringBuffer(); + val it = elements; + while(it.hasNext) { + sb.append(it.next.text); + } + sb.toString(); + } } diff --git a/sources/scala/xml/ProcInstr.scala b/sources/scala/xml/ProcInstr.scala index 08dd5c8feb..b4160139e6 100644 --- a/sources/scala/xml/ProcInstr.scala +++ b/sources/scala/xml/ProcInstr.scala @@ -16,12 +16,12 @@ package scala.xml; * @param text text contained in this node, may not contain "?>" **/ -case class ProcInstr(target:String, text:String) extends SpecialNode { +case class ProcInstr(target:String, proctext:String) extends SpecialNode { if( !Utility.isName( target ) ) throw new IllegalArgumentException(target+" must be an XML Name"); else if( text.indexOf("?>" ) != -1 ) - throw new IllegalArgumentException(text+" may not contain \"?>\""); + throw new IllegalArgumentException(proctext+" may not contain \"?>\""); final override def typeTag$:Int = -2; @@ -33,7 +33,7 @@ case class ProcInstr(target:String, text:String) extends SpecialNode { /** structural equality */ override def equals(x: Any): Boolean = x match { - case ProcInstr(x,y) => x.equals(target) && y.equals(text); + case ProcInstr(x,y) => x.equals(target) && y.equals(proctext); case _ => false } @@ -41,7 +41,10 @@ case class ProcInstr(target:String, text:String) extends SpecialNode { final def label = "#PI"; /** hashcode for this PI */ - override def hashCode() = target.hashCode() * 7 + text.hashCode(); + override def hashCode() = target.hashCode() * 7 + proctext.hashCode(); + + + override def text = ""; /** appends "<?" target (" "+text)?+"?>" * to this stringbuffer. @@ -50,7 +53,7 @@ case class ProcInstr(target:String, text:String) extends SpecialNode { sb .append("<?") .append(target); - if( text.length() > 0 ) { + if( proctext.length() > 0 ) { sb .append(' ') .append(text); diff --git a/sources/scala/xml/Text.scala b/sources/scala/xml/Text.scala index 5dc569b81c..507239cc8b 100644 --- a/sources/scala/xml/Text.scala +++ b/sources/scala/xml/Text.scala @@ -19,10 +19,6 @@ case class Text( _data: String ) extends Atom[String](_data) { if(null == data) throw new java.lang.NullPointerException("tried to construct Text with null"); - /** @deprecated - */ - def text = data.toString(); - final override def equals(x:Any) = x match { case s:String => s.equals( data.toString() ); case s:Text => data == s.data ; |