replaced StringBuffer with compat.StringBuilder (except in Java-specific file "FactoryAdapter") and added methods to stringbuilder

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@8097 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
emir 2006-07-11 15:15:02 +00:00
parent 473e2d4107
commit 7e709e613b
29 changed files with 133 additions and 103 deletions

View File

@ -14,14 +14,22 @@ package scala.runtime.compat;
class StringBuilder { class StringBuilder {
val str = new StringBuffer(); val str = new StringBuffer();
def charAt(i: int): char = str.charAt(i);
def append(x: Any): StringBuilder = { def append(x: Any): StringBuilder = {
str.append(x); str.append(x);
this this
} }
def append(x: char): StringBuilder = {
str.append(x);
this;
}
def append(x: String): StringBuilder = { def append(x: String): StringBuilder = {
str.append(x); str.append(x);
this this
} }
def length(): Int = str.length(); def length(): Int = str.length();
def setLength(i: int) = str.setLength(i)
override def toString() = str.toString(); override def toString() = str.toString();
} }

View File

@ -11,6 +11,7 @@
package scala.xml; package scala.xml;
import scala.runtime.compat.StringBuilder;
/** an XML node for text (PCDATA). Used in both non-bound and bound XML /** an XML node for text (PCDATA). Used in both non-bound and bound XML
* representations * representations
@ -36,7 +37,7 @@ class Atom[+A]( val data: A ) extends SpecialNode {
data.hashCode(); data.hashCode();
/** returns text, with some characters escaped according to XML spec */ /** returns text, with some characters escaped according to XML spec */
def toString(sb:StringBuffer) = def toString(sb: StringBuilder) =
Utility.escape( data.toString(), sb ); Utility.escape( data.toString(), sb );
override def text: String = data.toString(); override def text: String = data.toString();

View File

@ -11,6 +11,7 @@
package scala.xml; package scala.xml;
import scala.runtime.compat.StringBuilder;
/** an XML node for comments. /** an XML node for comments.
* *
@ -40,7 +41,7 @@ case class Comment(commentText: String) extends SpecialNode {
override def text = ""; override def text = "";
/** appends &quot;<!-- text -->&quot; to this stringbuffer */ /** appends &quot;<!-- text -->&quot; to this stringbuffer */
def toString(sb: StringBuffer) = { def toString(sb: StringBuilder) = {
sb.append("<!--").append(commentText).append("-->") sb.append("<!--").append(commentText).append("-->")
} }
} }

View File

@ -11,6 +11,7 @@
package scala.xml; package scala.xml;
import scala.runtime.compat.StringBuilder
/** The case class <code>Elem</code> extends the Node class, /** The case class <code>Elem</code> extends the Node class,
* providing an immutable data object representing an XML element. * providing an immutable data object representing an XML element.
@ -63,7 +64,7 @@ case class Elem(override val prefix: String,
/* returns concatenation of text(n) for each child n */ /* returns concatenation of text(n) for each child n */
override def text = { override def text = {
val sb = new StringBuffer(); val sb = new StringBuilder();
val it = child.elements; val it = child.elements;
while(it.hasNext) { while(it.hasNext) {
sb.append(it.next.text); sb.append(it.next.text);

View File

@ -11,6 +11,7 @@
package scala.xml; package scala.xml;
import scala.runtime.compat.StringBuilder
/** an XML node for entity references /** an XML node for entity references
* *
@ -40,10 +41,10 @@ case class EntityRef(entityName: String) extends SpecialNode {
case "amp" => "&"; case "amp" => "&";
case "apos" => "'"; case "apos" => "'";
case "quot" => "\""; case "quot" => "\"";
case _ => val sb=new StringBuffer();toString(sb).toString() case _ => val sb=new StringBuilder();toString(sb).toString()
} }
/** appends "&amp; entityName;" to this stringbuffer */ /** appends "&amp; entityName;" to this stringbuffer */
def toString(sb:StringBuffer) = def toString(sb:StringBuilder) =
sb.append("&").append(entityName).append(";"); sb.append("&").append(entityName).append(";");
} }

View File

@ -11,6 +11,7 @@
package scala.xml; package scala.xml;
import scala.runtime.compat.StringBuilder;
/** Attribute information item, and linked list of attribute information items. /** Attribute information item, and linked list of attribute information items.
* These are triples consisting of prefix,key,value. To obtain the namespace, * These are triples consisting of prefix,key,value. To obtain the namespace,
@ -136,21 +137,21 @@ abstract class MetaData extends Iterable[MetaData] {
override def hashCode(): Int; override def hashCode(): Int;
def toString1(): String = { def toString1(): String = {
val sb = new StringBuffer(); val sb = new StringBuilder();
toString1(sb); toString1(sb);
sb.toString(); sb.toString();
} }
//appends string representations of single attribute to StringBuffer //appends string representations of single attribute to StringBuilder
def toString1(sb:StringBuffer): Unit; def toString1(sb:StringBuilder): Unit;
override def toString(): String = { override def toString(): String = {
val sb = new StringBuffer(); val sb = new StringBuilder();
toString(sb); toString(sb);
sb.toString(); sb.toString();
} }
def toString(sb: StringBuffer): Unit = { def toString(sb: StringBuilder): Unit = {
sb.append(' '); sb.append(' ');
toString1(sb); toString1(sb);
next.toString(sb); next.toString(sb);

View File

@ -11,6 +11,7 @@
package scala.xml; package scala.xml;
import scala.runtime.compat.StringBuilder;
/** an XML node for a list of data items. /** an XML node for a list of data items.
* @author buraq * @author buraq
@ -36,7 +37,7 @@ class Molecule[+A]( val list: List[A] ) extends SpecialNode {
override def text = list.mkString(""," ",""); override def text = list.mkString(""," ","");
/** returns text, with some characters escaped according to XML spec */ /** returns text, with some characters escaped according to XML spec */
def toString(sb:StringBuffer) = def toString(sb:StringBuilder) =
sb.append(list.mkString(""," ","")) sb.append(list.mkString(""," ",""))
} }

View File

@ -11,6 +11,7 @@
package scala.xml; package scala.xml;
import scala.runtime.compat.StringBuilder
/** The class <code>NamespaceBinding</code> represents namespace bindings /** The class <code>NamespaceBinding</code> represents namespace bindings
* and scopes. The binding for the default namespace is treated as a null * and scopes. The binding for the default namespace is treated as a null
@ -42,18 +43,18 @@ class NamespaceBinding(val prefix: String,
if (_uri == uri) uri else parent.getURI(_uri); if (_uri == uri) uri else parent.getURI(_uri);
override def toString(): String = { override def toString(): String = {
val sb = new StringBuffer(); val sb = new StringBuilder();
toString(sb, TopScope); toString(sb, TopScope);
sb.toString(); sb.toString();
} }
def toString(stop: NamespaceBinding): String = { def toString(stop: NamespaceBinding): String = {
val sb = new StringBuffer(); val sb = new StringBuilder();
toString(sb, stop); toString(sb, stop);
sb.toString(); sb.toString();
} }
def toString(sb:StringBuffer, stop:NamespaceBinding): Unit = { def toString(sb:StringBuilder, stop:NamespaceBinding): Unit = {
if (this ne stop) { // contains? if (this ne stop) { // contains?
sb.append(" xmlns"); sb.append(" xmlns");
if (prefix != null) { if (prefix != null) {

View File

@ -11,6 +11,7 @@
package scala.xml; package scala.xml;
import scala.runtime.compat.StringBuilder
/** /**
* This object provides methods * This object provides methods
@ -150,12 +151,12 @@ abstract class Node extends NodeSeq {
override def toString(): String = toString(false); override def toString(): String = toString(false);
/** /**
* Appends qualified name of this node to <code>StringBuffer</code>. * Appends qualified name of this node to <code>StringBuilder</code>.
* *
* @param sb * @param sb
* @return .. * @return ..
*/ */
def nameToString(sb: StringBuffer): StringBuffer = { def nameToString(sb: StringBuilder): StringBuilder = {
if (null != prefix) { if (null != prefix) {
sb.append(prefix); sb.append(prefix);
sb.append(':'); sb.append(':');

View File

@ -11,6 +11,7 @@
package scala.xml; package scala.xml;
import scala.runtime.compat.StringBuilder
object NodeSeq { object NodeSeq {
final val Empty = new NodeSeq { def theSeq = Nil; } final val Empty = new NodeSeq { def theSeq = Nil; }
@ -98,7 +99,7 @@ abstract class NodeSeq extends Seq[Node] {
def filter(f:Node => Boolean): NodeSeq = { val x = toList filter f; x } def filter(f:Node => Boolean): NodeSeq = { val x = toList filter f; x }
def text: String = { def text: String = {
val sb = new StringBuffer(); val sb = new StringBuilder();
val it = elements; val it = elements;
while(it.hasNext) { while(it.hasNext) {
sb.append(it.next.text); sb.append(it.next.text);

View File

@ -11,6 +11,7 @@
package scala.xml; package scala.xml;
import scala.runtime.compat.StringBuilder
case object Null extends MetaData { case object Null extends MetaData {
@ -65,12 +66,12 @@ case object Null extends MetaData {
override def toString1(): String = ""; override def toString1(): String = "";
//appends string representations of single attribute to StringBuffer //appends string representations of single attribute to StringBuilder
def toString1(sb:StringBuffer) = {}; def toString1(sb:StringBuilder) = {};
override def toString(): String = ""; override def toString(): String = "";
override def toString(sb: StringBuffer): Unit = {} override def toString(sb: StringBuilder): Unit = {}
override def wellformed(scope: NamespaceBinding) = true; override def wellformed(scope: NamespaceBinding) = true;

View File

@ -11,6 +11,7 @@
package scala.xml; package scala.xml;
import scala.runtime.compat.StringBuilder
/** prefixed attributes always have a non-null namespace /** prefixed attributes always have a non-null namespace
*/ */
@ -72,7 +73,7 @@ class PrefixedAttribute(val pre: String,
pre.hashCode() * 41 + key.hashCode() * 7 + value.hashCode() * 3 + next.hashCode(); pre.hashCode() * 41 + key.hashCode() * 7 + value.hashCode() * 3 + next.hashCode();
def toString1(sb:StringBuffer): Unit = { def toString1(sb:StringBuilder): Unit = {
sb.append(pre); sb.append(pre);
sb.append(':'); sb.append(':');
sb.append(key); sb.append(key);

View File

@ -11,7 +11,7 @@
package scala.xml; package scala.xml;
import java.lang.StringBuffer ; /* Java dependency! */ import scala.runtime.compat.StringBuilder
import scala.collection.Map ; import scala.collection.Map ;
/** Class for pretty printing. After instantiating, you can use the /** Class for pretty printing. After instantiating, you can use the
@ -48,7 +48,7 @@ class PrettyPrinter( width:Int, step:Int ) {
val tmp = width - cur; val tmp = width - cur;
if( s.length() < tmp ) if( s.length() < tmp )
return List(Box(ind,s)); return List(Box(ind,s));
val sb = new StringBuffer(); val sb = new StringBuilder();
var i = s.indexOf(' '); var i = s.indexOf(' ');
if(i > tmp || i == -1) throw new BrokenException(); // cannot break if(i > tmp || i == -1) throw new BrokenException(); // cannot break
@ -97,7 +97,7 @@ class PrettyPrinter( width:Int, step:Int ) {
} }
protected def leafTag( n:Node ) = { protected def leafTag( n:Node ) = {
val sb = new StringBuffer("<"); val sb = new StringBuilder().append('<');
n.nameToString(sb); n.nameToString(sb);
//Utility.appendPrefixedName( n.prefix, n.label, pmap, sb ); //Utility.appendPrefixedName( n.prefix, n.label, pmap, sb );
n.attributes.toString(sb); n.attributes.toString(sb);
@ -107,7 +107,7 @@ class PrettyPrinter( width:Int, step:Int ) {
} }
protected def startTag(n: Node, pscope: NamespaceBinding): Pair[String, Int] = { protected def startTag(n: Node, pscope: NamespaceBinding): Pair[String, Int] = {
val sb = new StringBuffer("<"); val sb = new StringBuilder().append('<');
n.nameToString(sb); //Utility.appendPrefixedName( n.prefix, n.label, pmap, sb ); n.nameToString(sb); //Utility.appendPrefixedName( n.prefix, n.label, pmap, sb );
val i = sb.length() + 1; val i = sb.length() + 1;
n.attributes.toString(sb); n.attributes.toString(sb);
@ -117,7 +117,7 @@ class PrettyPrinter( width:Int, step:Int ) {
} }
protected def endTag(n: Node) = { protected def endTag(n: Node) = {
val sb = new StringBuffer("</"); val sb = new StringBuilder().append("</");
n.nameToString(sb); //Utility.appendPrefixedName( n.prefix, n.label, pmap, sb ); n.nameToString(sb); //Utility.appendPrefixedName( n.prefix, n.label, pmap, sb );
sb.append('>'); sb.append('>');
sb.toString(); sb.toString();
@ -150,7 +150,7 @@ class PrettyPrinter( width:Int, step:Int ) {
case _ => case _ =>
val test = { val test = {
val sb = new StringBuffer(); val sb = new StringBuilder();
Utility.toXML(node, pscope, sb, false); Utility.toXML(node, pscope, sb, false);
if(node.attribute("http://www.w3.org/XML/1998/namespace", "space") == "preserve") if(node.attribute("http://www.w3.org/XML/1998/namespace", "space") == "preserve")
sb.toString(); sb.toString();
@ -206,11 +206,11 @@ class PrettyPrinter( width:Int, step:Int ) {
* @param pmap the namespace to prefix mapping * @param pmap the namespace to prefix mapping
* @param sb the stringbuffer to append to * @param sb the stringbuffer to append to
*/ */
def format(n: Node, sb: StringBuffer ): Unit = { // entry point def format(n: Node, sb: StringBuilder ): Unit = { // entry point
format(n,null,sb) format(n,null,sb)
} }
def format(n: Node, pscope:NamespaceBinding, sb: StringBuffer): Unit = { // entry point def format(n: Node, pscope:NamespaceBinding, sb: StringBuilder): Unit = { // entry point
var lastwasbreak = false; var lastwasbreak = false;
reset(); reset();
traverse( n, pscope, 0 ); traverse( n, pscope, 0 );
@ -252,7 +252,7 @@ class PrettyPrinter( width:Int, step:Int ) {
* @param pmap the namespace to prefix mapping * @param pmap the namespace to prefix mapping
*/ */
def format(n: Node, pscope: NamespaceBinding): String = { def format(n: Node, pscope: NamespaceBinding): String = {
val sb = new StringBuffer(); val sb = new StringBuilder();
format( n, pscope, sb ); format( n, pscope, sb );
sb.toString(); sb.toString();
} }
@ -269,7 +269,7 @@ class PrettyPrinter( width:Int, step:Int ) {
* @param pmap the namespace to prefix mapping * @param pmap the namespace to prefix mapping
*/ */
def formatNodes( nodes:Seq[Node], pscope: NamespaceBinding ):String = { def formatNodes( nodes:Seq[Node], pscope: NamespaceBinding ):String = {
var sb = new StringBuffer(); var sb = new StringBuilder();
formatNodes( nodes, pscope, sb ); formatNodes( nodes, pscope, sb );
sb.toString(); sb.toString();
} }
@ -280,7 +280,7 @@ class PrettyPrinter( width:Int, step:Int ) {
* @param pmap the namespace to prefix mapping * @param pmap the namespace to prefix mapping
* @param sb the string buffer to which to append to * @param sb the string buffer to which to append to
*/ */
def formatNodes( nodes: Seq[Node], pscope: NamespaceBinding, sb: StringBuffer ): Unit = { def formatNodes( nodes: Seq[Node], pscope: NamespaceBinding, sb: StringBuilder ): Unit = {
for( val n <- nodes.elements ) { for( val n <- nodes.elements ) {
sb.append(format( n, pscope )) sb.append(format( n, pscope ))
} }

View File

@ -11,6 +11,7 @@
package scala.xml; package scala.xml;
import scala.runtime.compat.StringBuilder
/** an XML node for processing instructions (PI) /** an XML node for processing instructions (PI)
* *
@ -52,7 +53,7 @@ case class ProcInstr(target:String, proctext:String) extends SpecialNode {
/** appends &quot;&lt;?&quot; target (&quot; &quot;+text)?+&quot;?&gt;&quot; /** appends &quot;&lt;?&quot; target (&quot; &quot;+text)?+&quot;?&gt;&quot;
* to this stringbuffer. * to this stringbuffer.
*/ */
def toString(sb: StringBuffer) = { def toString(sb: StringBuilder) = {
sb sb
.append("<?") .append("<?")
.append(target); .append(target);

View File

@ -11,6 +11,7 @@
package scala.xml; package scala.xml;
import scala.runtime.compat.StringBuilder
/** a special XML node is either text (PCDATA), a comment, a PI, or /** a special XML node is either text (PCDATA), a comment, a PI, or
* an entity ref * an entity ref
@ -27,8 +28,8 @@ abstract class SpecialNode extends Node {
final def child = Nil; final def child = Nil;
final override def toString(): String = final override def toString(): String =
toString(new StringBuffer()).toString(); toString(new StringBuilder()).toString();
def toString(sb:StringBuffer): StringBuffer ; def toString(sb:StringBuilder): StringBuilder ;
} }

View File

@ -11,6 +11,7 @@
package scala.xml package scala.xml
import scala.runtime.compat.StringBuilder
/** an XML node for text (PCDATA). Used in both non-bound and bound XML /** an XML node for text (PCDATA). Used in both non-bound and bound XML
* representations * representations
@ -29,7 +30,7 @@ case class Text(_data: String) extends Atom[String](_data) {
} }
/** returns text, with some characters escaped according to XML spec */ /** returns text, with some characters escaped according to XML spec */
override def toString(sb: StringBuffer) = override def toString(sb: StringBuilder) =
Utility.escape(data.toString(), sb) Utility.escape(data.toString(), sb)
} }

View File

@ -11,6 +11,7 @@
package scala.xml; package scala.xml;
import scala.runtime.compat.StringBuilder;
object TextBuffer { object TextBuffer {
def fromString(str: String): TextBuffer = { def fromString(str: String): TextBuffer = {
@ -25,7 +26,7 @@ object TextBuffer {
*/ */
class TextBuffer { class TextBuffer {
val sb = new StringBuffer(); val sb = new StringBuilder();
var ws = true; var ws = true;
def appendSpace = if( !ws ) { ws = true; sb.append(' ');} else {}; def appendSpace = if( !ws ) { ws = true; sb.append(' ');} else {};

View File

@ -9,6 +9,8 @@
// $Id$ // $Id$
package scala.xml; package scala.xml;
import scala.runtime.compat.StringBuilder
/** top level namespace scope. only contains the predefined binding /** top level namespace scope. only contains the predefined binding
* for the &quot;xml&quot; prefix which is bound to * for the &quot;xml&quot; prefix which is bound to
* &quot;http://www.w3.org/XML/1998/namespace&quot; * &quot;http://www.w3.org/XML/1998/namespace&quot;
@ -31,6 +33,6 @@ case object TopScope extends NamespaceBinding(null, null, null) {
override def toString(stop: NamespaceBinding) = ""; override def toString(stop: NamespaceBinding) = "";
override def toString(sb: StringBuffer, ignore: NamespaceBinding) = {}; override def toString(sb: StringBuilder, ignore: NamespaceBinding) = {};
} }

View File

@ -11,6 +11,7 @@
package scala.xml; package scala.xml;
import scala.runtime.compat.StringBuilder
/** unprefixed attributes have the null namespace /** unprefixed attributes have the null namespace
*/ */
@ -59,7 +60,7 @@ class UnprefixedAttribute(val key: String, val value: String, val next: MetaData
/** returns false */ /** returns false */
final def isPrefixed = false; final def isPrefixed = false;
def toString1(sb:StringBuffer): Unit = { def toString1(sb:StringBuilder): Unit = {
sb.append(key); sb.append(key);
sb.append('='); sb.append('=');
Utility.appendQuoted(value, sb); Utility.appendQuoted(value, sb);

View File

@ -11,8 +11,7 @@
package scala.xml package scala.xml
import scala.runtime.compat.StringBuilder
import java.lang.StringBuffer
import scala.collection.mutable import scala.collection.mutable
/** /**
@ -25,10 +24,10 @@ object Utility extends AnyRef with parsing.TokenTests {
/* escapes the characters &lt; &gt; &amp; and &quot; from string */ /* escapes the characters &lt; &gt; &amp; and &quot; from string */
final def escape(text: String): String = final def escape(text: String): String =
escape(text, new StringBuffer()).toString() escape(text, new StringBuilder()).toString()
/* appends escaped string to s */ /* appends escaped string to s */
final def escape(text: String, s: StringBuffer): StringBuffer = { final def escape(text: String, s: StringBuilder): StringBuilder = {
for (val c <- Iterator.fromString(text)) c match { for (val c <- Iterator.fromString(text)) c match {
case '<' => s.append("&lt;") case '<' => s.append("&lt;")
case '>' => s.append("&gt;") case '>' => s.append("&gt;")
@ -83,7 +82,7 @@ object Utility extends AnyRef with parsing.TokenTests {
* @todo define a way to escape literal characters to &amp;xx; references * @todo define a way to escape literal characters to &amp;xx; references
*/ */
def toXML(n: Node, stripComment: Boolean): String = { def toXML(n: Node, stripComment: Boolean): String = {
val sb = new StringBuffer() val sb = new StringBuilder()
toXML(n, TopScope, sb, stripComment) toXML(n, TopScope, sb, stripComment)
sb.toString() sb.toString()
} }
@ -96,7 +95,7 @@ object Utility extends AnyRef with parsing.TokenTests {
* @param sb stringbuffer to append to * @param sb stringbuffer to append to
* @param stripComment if true, strip comments * @param stripComment if true, strip comments
*/ */
def toXML(x: Node, pscope: NamespaceBinding, sb: StringBuffer, stripComment: Boolean): Unit = { def toXML(x: Node, pscope: NamespaceBinding, sb: StringBuilder, stripComment: Boolean): Unit = {
x match { x match {
case c: Comment if !stripComment => case c: Comment if !stripComment =>
@ -159,23 +158,23 @@ object Utility extends AnyRef with parsing.TokenTests {
*/ */
def systemLiteralToString(s: String): String = { def systemLiteralToString(s: String): String = {
val sb = new StringBuffer() val sb = new StringBuilder()
systemLiteralToString(sb, s) systemLiteralToString(sb, s)
sb.toString() sb.toString()
} }
def systemLiteralToString(sb: StringBuffer, s: String): StringBuffer = { def systemLiteralToString(sb: StringBuilder, s: String): StringBuilder = {
sb.append("SYSTEM ") sb.append("SYSTEM ")
appendQuoted(s, sb) appendQuoted(s, sb)
} }
def publicLiteralToString(s: String): String = { def publicLiteralToString(s: String): String = {
val sb = new StringBuffer() val sb = new StringBuilder()
systemLiteralToString(sb, s) systemLiteralToString(sb, s)
sb.toString() sb.toString()
} }
def publicLiteralToString(sb: StringBuffer, s: String): StringBuffer = { def publicLiteralToString(sb: StringBuilder, s: String): StringBuilder = {
sb.append("PUBLIC \"").append(s).append('"') sb.append("PUBLIC \"").append(s).append('"')
} }
@ -186,7 +185,7 @@ object Utility extends AnyRef with parsing.TokenTests {
* @param s * @param s
* @param sb * @param sb
*/ */
def appendQuoted(s: String, sb: StringBuffer) = { def appendQuoted(s: String, sb: StringBuilder) = {
val ch = if (s.indexOf('"'.asInstanceOf[Int]) == -1) '"' else '\''; val ch = if (s.indexOf('"'.asInstanceOf[Int]) == -1) '"' else '\'';
sb.append(ch).append(s).append(ch) sb.append(ch).append(s).append(ch)
} }
@ -197,7 +196,7 @@ object Utility extends AnyRef with parsing.TokenTests {
* @param s * @param s
* @param sb * @param sb
*/ */
def appendEscapedQuoted(s: String, sb: StringBuffer) = { def appendEscapedQuoted(s: String, sb: StringBuilder) = {
sb.append('"') sb.append('"')
val z:Seq[Char] = Predef.string2seq(s) val z:Seq[Char] = Predef.string2seq(s)
for( val c <- z ) c match { for( val c <- z ) c match {
@ -209,7 +208,7 @@ object Utility extends AnyRef with parsing.TokenTests {
def getName(s: String, index: Int): String = { def getName(s: String, index: Int): String = {
var i = index; var i = index;
val sb = new StringBuffer(); val sb = new StringBuilder();
if (i < s.length()) { if (i < s.length()) {
var c = s.charAt(i); var c = s.charAt(i);
if (isNameStart(s.charAt(i))) if (isNameStart(s.charAt(i)))

View File

@ -11,7 +11,7 @@
package scala.xml.dtd; package scala.xml.dtd;
import scala.runtime.compat.StringBuilder;
import scala.util.regexp.WordExp; import scala.util.regexp.WordExp;
import scala.util.automata._; import scala.util.automata._;
@ -57,13 +57,13 @@ object ContentModel extends WordExp {
} }
def toString(r: RegExp):String = { def toString(r: RegExp):String = {
val sb = new StringBuffer(); val sb = new StringBuilder();
toString(r, sb); toString(r, sb);
sb.toString(); sb.toString();
} }
/* precond: rs.length >= 1 */ /* precond: rs.length >= 1 */
private def toString(rs: Seq[RegExp], sb: StringBuffer, sep: Char): Unit = { private def toString(rs: Seq[RegExp], sb: StringBuilder, sep: Char): Unit = {
val it = rs.elements; val it = rs.elements;
val fst = it.next; val fst = it.next;
@ -75,7 +75,7 @@ object ContentModel extends WordExp {
sb sb
} }
def toString(c: ContentModel, sb: StringBuffer): StringBuffer = c match { def toString(c: ContentModel, sb: StringBuilder): StringBuilder = c match {
case ANY => case ANY =>
sb.append("ANY"); sb.append("ANY");
@ -91,7 +91,7 @@ object ContentModel extends WordExp {
} }
def toString(r: RegExp, sb:StringBuffer): StringBuffer = { def toString(r: RegExp, sb:StringBuilder): StringBuilder = {
r match { r match {
case Eps => case Eps =>
sb sb
@ -115,12 +115,12 @@ object ContentModel extends WordExp {
sealed abstract class ContentModel { sealed abstract class ContentModel {
override def toString(): String = { override def toString(): String = {
val sb = new StringBuffer(); val sb = new StringBuilder();
toString(sb); toString(sb);
sb.toString(); sb.toString();
} }
def toString(sb:StringBuffer): StringBuffer; def toString(sb:StringBuilder): StringBuilder;
/* /*
def validate(cs: NodeSeq): Boolean = this.match { def validate(cs: NodeSeq): Boolean = this.match {
case ANY => true ; case ANY => true ;
@ -134,13 +134,13 @@ sealed abstract class ContentModel {
} }
case object PCDATA extends ContentModel { case object PCDATA extends ContentModel {
def toString(sb:StringBuffer): StringBuffer = sb.append("(#PCDATA)"); def toString(sb:StringBuilder): StringBuilder = sb.append("(#PCDATA)");
} }
case object EMPTY extends ContentModel { case object EMPTY extends ContentModel {
def toString(sb:StringBuffer): StringBuffer = sb.append("EMPTY"); def toString(sb:StringBuilder): StringBuilder = sb.append("EMPTY");
} }
case object ANY extends ContentModel { case object ANY extends ContentModel {
def toString(sb:StringBuffer): StringBuffer = sb.append("ANY"); def toString(sb:StringBuilder): StringBuilder = sb.append("ANY");
} }
abstract class DFAContentModel extends ContentModel { abstract class DFAContentModel extends ContentModel {
import ContentModel.{ ElemName }; import ContentModel.{ ElemName };
@ -178,7 +178,7 @@ Console.println("ns = "+ns);
} }
} }
*/ */
def toString(sb:StringBuffer): StringBuffer = { def toString(sb:StringBuilder): StringBuilder = {
sb.append("(#PCDATA|"); sb.append("(#PCDATA|");
//r match { //r match {
// case Alt(Eps, rs@_*) => ContentModel.toString(Alt(rs:_*):RegExp, sb); // case Alt(Eps, rs@_*) => ContentModel.toString(Alt(rs:_*):RegExp, sb);
@ -207,6 +207,6 @@ case class ELEMENTS(r:ContentModel.RegExp) extends DFAContentModel {
} }
} }
*/ */
def toString(sb:StringBuffer): StringBuffer = def toString(sb:StringBuilder): StringBuilder =
ContentModel.toString(r, sb); ContentModel.toString(r, sb);
} }

View File

@ -11,7 +11,7 @@
package scala.xml.dtd; package scala.xml.dtd;
import scala.runtime.compat.StringBuilder
import scala.collection.mutable.{ HashMap, Map } import scala.collection.mutable.{ HashMap, Map }
/** a document type declaration */ /** a document type declaration */
@ -36,7 +36,7 @@ abstract class DTD {
//def getAttribDecl(elem: String, attr: String): AttrDecl; //def getAttribDecl(elem: String, attr: String): AttrDecl;
override def toString() = { override def toString() = {
val sb = new StringBuffer(); val sb = new StringBuilder();
sb.append("DTD [\n"); sb.append("DTD [\n");
if(null != externalID) if(null != externalID)
sb.append(externalID.toString()).append('\n'); sb.append(externalID.toString()).append('\n');

View File

@ -11,16 +11,17 @@
package scala.xml.dtd; package scala.xml.dtd;
import scala.runtime.compat.StringBuilder
abstract class Decl; abstract class Decl;
abstract class MarkupDecl extends Decl { abstract class MarkupDecl extends Decl {
final override def toString(): String = { final override def toString(): String = {
toString(new StringBuffer()).toString(); toString(new StringBuilder()).toString();
} }
def toString(sb: StringBuffer): StringBuffer; def toString(sb: StringBuilder): StringBuilder;
} }
@ -30,7 +31,7 @@ case class ElemDecl(name: String, contentModel: ContentModel) extends MarkupDecl
//def mixed = ; // to do //def mixed = ; // to do
def toString(sb: StringBuffer): StringBuffer = { def toString(sb: StringBuilder): StringBuilder = {
sb sb
.append("<!ELEMENT ") .append("<!ELEMENT ")
.append(name) .append(name)
@ -44,7 +45,7 @@ case class ElemDecl(name: String, contentModel: ContentModel) extends MarkupDecl
case class AttListDecl(name: String, attrs:List[AttrDecl]) extends MarkupDecl with DtdTypeSymbol { case class AttListDecl(name: String, attrs:List[AttrDecl]) extends MarkupDecl with DtdTypeSymbol {
def toString(sb: StringBuffer): StringBuffer = { def toString(sb: StringBuilder): StringBuilder = {
sb sb
.append("<!ATTLIST ") .append("<!ATTLIST ")
.append(name) .append(name)
@ -60,9 +61,9 @@ case class AttListDecl(name: String, attrs:List[AttrDecl]) extends MarkupDecl wi
case class AttrDecl( name:String, tpe:String, default:DefaultDecl ) { case class AttrDecl( name:String, tpe:String, default:DefaultDecl ) {
final override def toString(): String = final override def toString(): String =
toString(new StringBuffer()).toString(); toString(new StringBuilder()).toString();
final def toString(sb: StringBuffer): StringBuffer = { final def toString(sb: StringBuilder): StringBuilder = {
sb.append(" ").append( name ).append(' ').append( tpe ).append(' '); sb.append(" ").append( name ).append(' ').append( tpe ).append(' ');
default.toString(sb) default.toString(sb)
} }
@ -75,7 +76,7 @@ abstract class EntityDecl extends MarkupDecl;
/** a parsed general entity declaration */ /** a parsed general entity declaration */
case class ParsedEntityDecl( name:String, entdef:EntityDef ) extends EntityDecl { case class ParsedEntityDecl( name:String, entdef:EntityDef ) extends EntityDecl {
final def toString(sb: StringBuffer): StringBuffer = { final def toString(sb: StringBuilder): StringBuilder = {
sb.append("<!ENTITY ").append( name ).append(' '); sb.append("<!ENTITY ").append( name ).append(' ');
entdef.toString(sb).append('>'); entdef.toString(sb).append('>');
} }
@ -84,7 +85,7 @@ case class ParsedEntityDecl( name:String, entdef:EntityDef ) extends EntityDecl
/** a parameter entity declaration */ /** a parameter entity declaration */
case class ParameterEntityDecl(name: String, entdef: EntityDef) extends EntityDecl { case class ParameterEntityDecl(name: String, entdef: EntityDef) extends EntityDecl {
final def toString(sb: StringBuffer): StringBuffer = { final def toString(sb: StringBuilder): StringBuilder = {
sb.append("<!ENTITY % ").append( name ).append(' '); sb.append("<!ENTITY % ").append( name ).append(' ');
entdef.toString(sb).append('>'); entdef.toString(sb).append('>');
} }
@ -92,14 +93,14 @@ case class ParameterEntityDecl(name: String, entdef: EntityDef) extends EntityDe
/** an unparsed entity declaration */ /** an unparsed entity declaration */
case class UnparsedEntityDecl( name:String, extID:ExternalID, notation:String ) extends EntityDecl { case class UnparsedEntityDecl( name:String, extID:ExternalID, notation:String ) extends EntityDecl {
final def toString(sb: StringBuffer): StringBuffer = { final def toString(sb: StringBuilder): StringBuilder = {
sb.append("<!ENTITY ").append( name ).append(' '); sb.append("<!ENTITY ").append( name ).append(' ');
extID.toString(sb).append(" NDATA ").append(notation).append('>'); extID.toString(sb).append(" NDATA ").append(notation).append('>');
} }
} }
/** a notation declaration */ /** a notation declaration */
case class NotationDecl( name:String, extID:ExternalID ) extends MarkupDecl { case class NotationDecl( name:String, extID:ExternalID ) extends MarkupDecl {
final def toString(sb: StringBuffer): StringBuffer = { final def toString(sb: StringBuilder): StringBuilder = {
sb.append("<!NOTATION ").append( name ).append(' '); sb.append("<!NOTATION ").append( name ).append(' ');
extID.toString(sb); extID.toString(sb);
} }
@ -107,9 +108,9 @@ case class NotationDecl( name:String, extID:ExternalID ) extends MarkupDecl {
abstract class EntityDef { abstract class EntityDef {
final override def toString(): String = final override def toString(): String =
toString(new StringBuffer()).toString(); toString(new StringBuilder()).toString();
def toString(sb: StringBuffer): StringBuffer; def toString(sb: StringBuilder): StringBuilder;
} }
case class IntDef(value:String) extends EntityDef { case class IntDef(value:String) extends EntityDef {
@ -133,13 +134,13 @@ case class IntDef(value:String) extends EntityDef {
} }
validateValue(); validateValue();
final def toString(sb: StringBuffer): StringBuffer = final def toString(sb: StringBuilder): StringBuilder =
Utility.appendQuoted(value, sb); Utility.appendQuoted(value, sb);
} }
case class ExtDef(extID:ExternalID) extends EntityDef { case class ExtDef(extID:ExternalID) extends EntityDef {
final def toString(sb: StringBuffer): StringBuffer = final def toString(sb: StringBuilder): StringBuilder =
extID.toString(sb); extID.toString(sb);
} }
@ -150,7 +151,7 @@ case class PEReference(ent:String) extends MarkupDecl {
if( !Utility.isName( ent )) if( !Utility.isName( ent ))
throw new IllegalArgumentException("ent must be an XML Name"); throw new IllegalArgumentException("ent must be an XML Name");
final def toString(sb: StringBuffer): StringBuffer = final def toString(sb: StringBuilder): StringBuilder =
sb.append('%').append(ent).append(';'); sb.append('%').append(ent).append(';');
} }
@ -159,24 +160,24 @@ case class PEReference(ent:String) extends MarkupDecl {
abstract class DefaultDecl { abstract class DefaultDecl {
override def toString(): String; override def toString(): String;
def toString(sb: StringBuffer): StringBuffer; def toString(sb: StringBuilder): StringBuilder;
} }
case object REQUIRED extends DefaultDecl { case object REQUIRED extends DefaultDecl {
final override def toString(): String = "#REQUIRED"; final override def toString(): String = "#REQUIRED";
final def toString(sb:StringBuffer) = sb.append("#REQUIRED"); final def toString(sb:StringBuilder) = sb.append("#REQUIRED");
} }
case object IMPLIED extends DefaultDecl { case object IMPLIED extends DefaultDecl {
final override def toString(): String = "#IMPLIED"; final override def toString(): String = "#IMPLIED";
final def toString(sb:StringBuffer) = sb.append("#IMPLIED"); final def toString(sb:StringBuilder) = sb.append("#IMPLIED");
} }
case class DEFAULT(fixed: Boolean, attValue:String) extends DefaultDecl { case class DEFAULT(fixed: Boolean, attValue:String) extends DefaultDecl {
final override def toString(): String = final override def toString(): String =
toString(new StringBuffer()).toString(); toString(new StringBuilder()).toString();
final def toString(sb:StringBuffer): StringBuffer = { final def toString(sb:StringBuilder): StringBuilder = {
if(fixed) if(fixed)
sb.append("#FIXED "); sb.append("#FIXED ");
Utility.appendEscapedQuoted( attValue, sb ); Utility.appendEscapedQuoted( attValue, sb );

View File

@ -11,6 +11,7 @@
package scala.xml.dtd; package scala.xml.dtd;
import scala.runtime.compat.StringBuilder
/** an XML node for document type declaration /** an XML node for document type declaration
* *
@ -30,7 +31,7 @@ case class DocType( name:String, extID:ExternalID, intSubset:Seq[dtd.Decl]) {
/** returns "&lt;!DOCTYPE + name + extID? + ("["+intSubSet+"]")? >" */ /** returns "&lt;!DOCTYPE + name + extID? + ("["+intSubSet+"]")? >" */
final override def toString() = { final override def toString() = {
val sb = new StringBuffer("<!DOCTYPE "); val sb = new StringBuilder().append("<!DOCTYPE ");
sb.append( name ); sb.append( name );
sb.append(' '); sb.append(' ');
sb.append(extID.toString()); sb.append(extID.toString());

View File

@ -11,6 +11,7 @@
package scala.xml.dtd; package scala.xml.dtd;
import scala.runtime.compat.StringBuilder
/** an ExternalIDs - either PublicID or SystemID /** an ExternalIDs - either PublicID or SystemID
* *
@ -25,7 +26,7 @@ abstract class ExternalID {
override def toString(): String; override def toString(): String;
/** returns "PUBLIC "+publicLiteral+" SYSTEM "+systemLiteral */ /** returns "PUBLIC "+publicLiteral+" SYSTEM "+systemLiteral */
def toString(sb: StringBuffer): StringBuffer; def toString(sb: StringBuilder): StringBuilder;
def systemId: String; def systemId: String;
@ -47,7 +48,7 @@ case class SystemID( systemId:String ) extends ExternalID with parsing.TokenTest
final override def toString() = final override def toString() =
Utility.systemLiteralToString( systemId ); Utility.systemLiteralToString( systemId );
final def toString(sb: StringBuffer): StringBuffer = final def toString(sb: StringBuilder): StringBuilder =
Utility.systemLiteralToString( sb, systemId ); Utility.systemLiteralToString( sb, systemId );
} }
@ -83,11 +84,11 @@ case class PublicID( publicId:String, systemId:String ) extends ExternalID with
/** returns "PUBLIC "+publicId+" SYSTEM "+systemId */ /** returns "PUBLIC "+publicId+" SYSTEM "+systemId */
final override def toString(): String = { final override def toString(): String = {
toString(new StringBuffer()).toString(); toString(new StringBuilder()).toString();
} }
/** appends "PUBLIC "+publicId+" SYSTEM "+systemId to argument */ /** appends "PUBLIC "+publicId+" SYSTEM "+systemId to argument */
final def toString(sb: StringBuffer): StringBuffer = { final def toString(sb: StringBuilder): StringBuilder = {
Utility.publicLiteralToString( sb, publicId ).append(' '); Utility.publicLiteralToString( sb, publicId ).append(' ');
if(systemId!=null) if(systemId!=null)
Utility.systemLiteralToString( sb, systemId ); Utility.systemLiteralToString( sb, systemId );

View File

@ -11,6 +11,7 @@
package scala.xml.dtd; package scala.xml.dtd;
import scala.runtime.compat.StringBuilder
/** Scanner for regexps (content models in DTD element declarations) /** Scanner for regexps (content models in DTD element declarations)
* todo: cleanup * todo: cleanup
@ -90,7 +91,7 @@ class Scanner extends Tokens with parsing.TokenTests {
} }
final def name = { final def name = {
val sb = new StringBuffer(); val sb = new StringBuilder();
do { sb.append( c ); next } while ( isNameChar( c ) ) ; do { sb.append( c ); next } while ( isNameChar( c ) ) ;
value = sb.toString(); value = sb.toString();
NAME NAME

View File

@ -11,6 +11,7 @@
package scala.xml.dtd; package scala.xml.dtd;
import scala.runtime.compat.StringBuilder
case class ValidationException( e:String ) extends Exception( e ); case class ValidationException( e:String ) extends Exception( e );
@ -28,7 +29,7 @@ object MakeValidationException {
new ValidationException("attribute " + key +" not allowed here" ); new ValidationException("attribute " + key +" not allowed here" );
def fromMissingAttribute( allKeys:scala.collection.Set[String] ) = { def fromMissingAttribute( allKeys:scala.collection.Set[String] ) = {
val sb = new StringBuffer(); val sb = new StringBuilder();
sb.append("missing value for REQUIRED attribute"); sb.append("missing value for REQUIRED attribute");
if( allKeys.size > 1 ) sb.append('s'); if( allKeys.size > 1 ) sb.append('s');
val it = allKeys.elements; val it = allKeys.elements;

View File

@ -11,7 +11,7 @@
package scala.xml.parsing; package scala.xml.parsing;
import scala.runtime.compat.StringBuilder
import scala.io.Source; import scala.io.Source;
import java.net._; import java.net._;
import java.io._; import java.io._;
@ -26,7 +26,7 @@ trait ExternalSources requires (ExternalSources with MarkupParser with MarkupHan
//@todo: replace this hack with proper Source implementation //@todo: replace this hack with proper Source implementation
val str = new StringBuffer(); val str = new StringBuilder();
var inputLine:String = null; var inputLine:String = null;
//while (inputLine = in.readLine()) != null) { //while (inputLine = in.readLine()) != null) {

View File

@ -11,7 +11,7 @@
package scala.xml.parsing; package scala.xml.parsing;
import scala.runtime.compat.StringBuilder
import scala.io.Source; import scala.io.Source;
import scala.xml.dtd._ ; import scala.xml.dtd._ ;
@ -61,7 +61,7 @@ trait MarkupParser requires (MarkupParser with MarkupHandler) extends AnyRef wit
var ch: Char = _; var ch: Char = _;
/** character buffer, for names */ /** character buffer, for names */
protected val cbuf = new StringBuffer(); protected val cbuf = new StringBuilder();
var dtd: DTD = null; var dtd: DTD = null;
@ -392,7 +392,7 @@ trait MarkupParser requires (MarkupParser with MarkupHandler) extends AnyRef wit
def xCharData: NodeSeq = { def xCharData: NodeSeq = {
xToken("[CDATA["); xToken("[CDATA[");
val pos1 = pos; val pos1 = pos;
val sb: StringBuffer = new StringBuffer(); val sb: StringBuilder = new StringBuilder();
while (true) { while (true) {
if (ch==']' && if (ch==']' &&
{ sb.append(ch); nextch; ch == ']' } && { sb.append(ch); nextch; ch == ']' } &&
@ -440,7 +440,7 @@ trait MarkupParser requires (MarkupParser with MarkupHandler) extends AnyRef wit
* see [15] * see [15]
*/ */
def xComment: NodeSeq = { def xComment: NodeSeq = {
val sb: StringBuffer = new StringBuffer(); val sb: StringBuilder = new StringBuilder();
xToken('-'); xToken('-');
xToken('-'); xToken('-');
while (true) { while (true) {
@ -455,7 +455,7 @@ trait MarkupParser requires (MarkupParser with MarkupHandler) extends AnyRef wit
throw FatalError("this cannot happen"); throw FatalError("this cannot happen");
}; };
/* todo: move this into the NodeBuffer class */ /* todo: move this into the NodeBuilder class */
def appendText(pos: Int, ts: NodeBuffer, txt: String): Unit = { def appendText(pos: Int, ts: NodeBuffer, txt: String): Unit = {
if (preserveWS) if (preserveWS)
ts &+ handle.text(pos, txt); ts &+ handle.text(pos, txt);
@ -510,7 +510,7 @@ trait MarkupParser requires (MarkupParser with MarkupHandler) extends AnyRef wit
/* if( xCheckEmbeddedBlock ) { /* if( xCheckEmbeddedBlock ) {
ts.appendAll(xEmbeddedExpr); ts.appendAll(xEmbeddedExpr);
} else {*/ } else {*/
// val str = new StringBuffer("{"); // val str = new StringBuilder("{");
// str.append(xText); // str.append(xText);
// appendText(tmppos, ts, str.toString()); // appendText(tmppos, ts, str.toString());
/*}*/ /*}*/
@ -731,7 +731,7 @@ trait MarkupParser requires (MarkupParser with MarkupHandler) extends AnyRef wit
* see [15] * see [15]
*/ */
def xProcInstr: NodeSeq = { def xProcInstr: NodeSeq = {
val sb:StringBuffer = new StringBuffer(); val sb:StringBuilder = new StringBuilder();
val n = xName; val n = xName;
if (isSpace(ch)) { if (isSpace(ch)) {
xSpace; xSpace;
@ -1197,7 +1197,7 @@ trait MarkupParser requires (MarkupParser with MarkupHandler) extends AnyRef wit
val s = xCharRef ({ () => c }, { () => c = it.next }); val s = xCharRef ({ () => c }, { () => c = it.next });
cbuf.append(s); cbuf.append(s);
case nchar => case nchar =>
val nbuf = new StringBuffer(); val nbuf = new StringBuilder();
var d = nchar; var d = nchar;
do { do {
nbuf.append(d); nbuf.append(d);