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 {
val str = new StringBuffer();
def charAt(i: int): char = str.charAt(i);
def append(x: Any): StringBuilder = {
str.append(x);
this
}
def append(x: char): StringBuilder = {
str.append(x);
this;
}
def append(x: String): StringBuilder = {
str.append(x);
this
}
def length(): Int = str.length();
def setLength(i: int) = str.setLength(i)
override def toString() = str.toString();
}

View File

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

View File

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

View File

@ -11,6 +11,7 @@
package scala.xml;
import scala.runtime.compat.StringBuilder
/** The case class <code>Elem</code> extends the Node class,
* 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 */
override def text = {
val sb = new StringBuffer();
val sb = new StringBuilder();
val it = child.elements;
while(it.hasNext) {
sb.append(it.next.text);

View File

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

View File

@ -11,6 +11,7 @@
package scala.xml;
import scala.runtime.compat.StringBuilder;
/** Attribute information item, and linked list of attribute information items.
* 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;
def toString1(): String = {
val sb = new StringBuffer();
val sb = new StringBuilder();
toString1(sb);
sb.toString();
}
//appends string representations of single attribute to StringBuffer
def toString1(sb:StringBuffer): Unit;
//appends string representations of single attribute to StringBuilder
def toString1(sb:StringBuilder): Unit;
override def toString(): String = {
val sb = new StringBuffer();
val sb = new StringBuilder();
toString(sb);
sb.toString();
}
def toString(sb: StringBuffer): Unit = {
def toString(sb: StringBuilder): Unit = {
sb.append(' ');
toString1(sb);
next.toString(sb);

View File

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

View File

@ -11,6 +11,7 @@
package scala.xml;
import scala.runtime.compat.StringBuilder
/** The class <code>NamespaceBinding</code> represents namespace bindings
* 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);
override def toString(): String = {
val sb = new StringBuffer();
val sb = new StringBuilder();
toString(sb, TopScope);
sb.toString();
}
def toString(stop: NamespaceBinding): String = {
val sb = new StringBuffer();
val sb = new StringBuilder();
toString(sb, stop);
sb.toString();
}
def toString(sb:StringBuffer, stop:NamespaceBinding): Unit = {
def toString(sb:StringBuilder, stop:NamespaceBinding): Unit = {
if (this ne stop) { // contains?
sb.append(" xmlns");
if (prefix != null) {

View File

@ -11,6 +11,7 @@
package scala.xml;
import scala.runtime.compat.StringBuilder
/**
* This object provides methods
@ -150,12 +151,12 @@ abstract class Node extends NodeSeq {
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
* @return ..
*/
def nameToString(sb: StringBuffer): StringBuffer = {
def nameToString(sb: StringBuilder): StringBuilder = {
if (null != prefix) {
sb.append(prefix);
sb.append(':');

View File

@ -11,6 +11,7 @@
package scala.xml;
import scala.runtime.compat.StringBuilder
object NodeSeq {
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 text: String = {
val sb = new StringBuffer();
val sb = new StringBuilder();
val it = elements;
while(it.hasNext) {
sb.append(it.next.text);

View File

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

View File

@ -11,6 +11,7 @@
package scala.xml;
import scala.runtime.compat.StringBuilder
/** 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();
def toString1(sb:StringBuffer): Unit = {
def toString1(sb:StringBuilder): Unit = {
sb.append(pre);
sb.append(':');
sb.append(key);

View File

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

View File

@ -11,6 +11,7 @@
package scala.xml;
import scala.runtime.compat.StringBuilder
/** 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;
* to this stringbuffer.
*/
def toString(sb: StringBuffer) = {
def toString(sb: StringBuilder) = {
sb
.append("<?")
.append(target);

View File

@ -11,6 +11,7 @@
package scala.xml;
import scala.runtime.compat.StringBuilder
/** a special XML node is either text (PCDATA), a comment, a PI, or
* an entity ref
@ -27,8 +28,8 @@ abstract class SpecialNode extends Node {
final def child = Nil;
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
import scala.runtime.compat.StringBuilder
/** an XML node for text (PCDATA). Used in both non-bound and bound XML
* representations
@ -29,7 +30,7 @@ case class Text(_data: String) extends Atom[String](_data) {
}
/** 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)
}

View File

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

View File

@ -9,6 +9,8 @@
// $Id$
package scala.xml;
import scala.runtime.compat.StringBuilder
/** top level namespace scope. only contains the predefined binding
* for the &quot;xml&quot; prefix which is bound to
* &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(sb: StringBuffer, ignore: NamespaceBinding) = {};
override def toString(sb: StringBuilder, ignore: NamespaceBinding) = {};
}

View File

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

View File

@ -11,8 +11,7 @@
package scala.xml
import java.lang.StringBuffer
import scala.runtime.compat.StringBuilder
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 */
final def escape(text: String): String =
escape(text, new StringBuffer()).toString()
escape(text, new StringBuilder()).toString()
/* 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 {
case '<' => s.append("&lt;")
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
*/
def toXML(n: Node, stripComment: Boolean): String = {
val sb = new StringBuffer()
val sb = new StringBuilder()
toXML(n, TopScope, sb, stripComment)
sb.toString()
}
@ -96,7 +95,7 @@ object Utility extends AnyRef with parsing.TokenTests {
* @param sb stringbuffer to append to
* @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 {
case c: Comment if !stripComment =>
@ -159,23 +158,23 @@ object Utility extends AnyRef with parsing.TokenTests {
*/
def systemLiteralToString(s: String): String = {
val sb = new StringBuffer()
val sb = new StringBuilder()
systemLiteralToString(sb, s)
sb.toString()
}
def systemLiteralToString(sb: StringBuffer, s: String): StringBuffer = {
def systemLiteralToString(sb: StringBuilder, s: String): StringBuilder = {
sb.append("SYSTEM ")
appendQuoted(s, sb)
}
def publicLiteralToString(s: String): String = {
val sb = new StringBuffer()
val sb = new StringBuilder()
systemLiteralToString(sb, s)
sb.toString()
}
def publicLiteralToString(sb: StringBuffer, s: String): StringBuffer = {
def publicLiteralToString(sb: StringBuilder, s: String): StringBuilder = {
sb.append("PUBLIC \"").append(s).append('"')
}
@ -186,7 +185,7 @@ object Utility extends AnyRef with parsing.TokenTests {
* @param s
* @param sb
*/
def appendQuoted(s: String, sb: StringBuffer) = {
def appendQuoted(s: String, sb: StringBuilder) = {
val ch = if (s.indexOf('"'.asInstanceOf[Int]) == -1) '"' else '\'';
sb.append(ch).append(s).append(ch)
}
@ -197,7 +196,7 @@ object Utility extends AnyRef with parsing.TokenTests {
* @param s
* @param sb
*/
def appendEscapedQuoted(s: String, sb: StringBuffer) = {
def appendEscapedQuoted(s: String, sb: StringBuilder) = {
sb.append('"')
val z:Seq[Char] = Predef.string2seq(s)
for( val c <- z ) c match {
@ -209,7 +208,7 @@ object Utility extends AnyRef with parsing.TokenTests {
def getName(s: String, index: Int): String = {
var i = index;
val sb = new StringBuffer();
val sb = new StringBuilder();
if (i < s.length()) {
var c = s.charAt(i);
if (isNameStart(s.charAt(i)))

View File

@ -11,7 +11,7 @@
package scala.xml.dtd;
import scala.runtime.compat.StringBuilder;
import scala.util.regexp.WordExp;
import scala.util.automata._;
@ -57,13 +57,13 @@ object ContentModel extends WordExp {
}
def toString(r: RegExp):String = {
val sb = new StringBuffer();
val sb = new StringBuilder();
toString(r, sb);
sb.toString();
}
/* 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 fst = it.next;
@ -75,7 +75,7 @@ object ContentModel extends WordExp {
sb
}
def toString(c: ContentModel, sb: StringBuffer): StringBuffer = c match {
def toString(c: ContentModel, sb: StringBuilder): StringBuilder = c match {
case 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 {
case Eps =>
sb
@ -115,12 +115,12 @@ object ContentModel extends WordExp {
sealed abstract class ContentModel {
override def toString(): String = {
val sb = new StringBuffer();
val sb = new StringBuilder();
toString(sb);
sb.toString();
}
def toString(sb:StringBuffer): StringBuffer;
def toString(sb:StringBuilder): StringBuilder;
/*
def validate(cs: NodeSeq): Boolean = this.match {
case ANY => true ;
@ -134,13 +134,13 @@ sealed abstract class 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 {
def toString(sb:StringBuffer): StringBuffer = sb.append("EMPTY");
def toString(sb:StringBuilder): StringBuilder = sb.append("EMPTY");
}
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 {
import ContentModel.{ ElemName };
@ -178,7 +178,7 @@ Console.println("ns = "+ns);
}
}
*/
def toString(sb:StringBuffer): StringBuffer = {
def toString(sb:StringBuilder): StringBuilder = {
sb.append("(#PCDATA|");
//r match {
// 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);
}

View File

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

View File

@ -11,16 +11,17 @@
package scala.xml.dtd;
import scala.runtime.compat.StringBuilder
abstract class Decl;
abstract class MarkupDecl extends Decl {
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 toString(sb: StringBuffer): StringBuffer = {
def toString(sb: StringBuilder): StringBuilder = {
sb
.append("<!ELEMENT ")
.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 {
def toString(sb: StringBuffer): StringBuffer = {
def toString(sb: StringBuilder): StringBuilder = {
sb
.append("<!ATTLIST ")
.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 ) {
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(' ');
default.toString(sb)
}
@ -75,7 +76,7 @@ abstract class EntityDecl extends MarkupDecl;
/** a parsed general entity declaration */
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(' ');
entdef.toString(sb).append('>');
}
@ -84,7 +85,7 @@ case class ParsedEntityDecl( name:String, entdef:EntityDef ) extends EntityDecl
/** a parameter entity declaration */
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(' ');
entdef.toString(sb).append('>');
}
@ -92,14 +93,14 @@ case class ParameterEntityDecl(name: String, entdef: EntityDef) extends EntityDe
/** an unparsed entity declaration */
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(' ');
extID.toString(sb).append(" NDATA ").append(notation).append('>');
}
}
/** a notation declaration */
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(' ');
extID.toString(sb);
}
@ -107,9 +108,9 @@ case class NotationDecl( name:String, extID:ExternalID ) extends MarkupDecl {
abstract class EntityDef {
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 {
@ -133,13 +134,13 @@ case class IntDef(value:String) extends EntityDef {
}
validateValue();
final def toString(sb: StringBuffer): StringBuffer =
final def toString(sb: StringBuilder): StringBuilder =
Utility.appendQuoted(value, sb);
}
case class ExtDef(extID:ExternalID) extends EntityDef {
final def toString(sb: StringBuffer): StringBuffer =
final def toString(sb: StringBuilder): StringBuilder =
extID.toString(sb);
}
@ -150,7 +151,7 @@ case class PEReference(ent:String) extends MarkupDecl {
if( !Utility.isName( ent ))
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(';');
}
@ -159,24 +160,24 @@ case class PEReference(ent:String) extends MarkupDecl {
abstract class DefaultDecl {
override def toString(): String;
def toString(sb: StringBuffer): StringBuffer;
def toString(sb: StringBuilder): StringBuilder;
}
case object REQUIRED extends DefaultDecl {
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 {
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 {
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)
sb.append("#FIXED ");
Utility.appendEscapedQuoted( attValue, sb );

View File

@ -11,6 +11,7 @@
package scala.xml.dtd;
import scala.runtime.compat.StringBuilder
/** 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+"]")? >" */
final override def toString() = {
val sb = new StringBuffer("<!DOCTYPE ");
val sb = new StringBuilder().append("<!DOCTYPE ");
sb.append( name );
sb.append(' ');
sb.append(extID.toString());

View File

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

View File

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

View File

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

View File

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

View File

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