summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-04-30 19:48:53 +0000
committerPaul Phillips <paulp@improving.org>2009-04-30 19:48:53 +0000
commitc045524ead5b916ffec9cc7d942ee775c50875ec (patch)
tree9cff09f4a8b6a9135c86667d3f587a3b6fec3d70 /src/library
parent8906512f68edb9c323ddc2fce56d51d34e687394 (diff)
downloadscala-c045524ead5b916ffec9cc7d942ee775c50875ec.tar.gz
scala-c045524ead5b916ffec9cc7d942ee775c50875ec.tar.bz2
scala-c045524ead5b916ffec9cc7d942ee775c50875ec.zip
Some minor cleanups made in the course of looki...
Some minor cleanups made in the course of looking into bugs #1488 and #1489.
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/xml/Utility.scala51
-rw-r--r--src/library/scala/xml/dtd/ExternalID.scala67
2 files changed, 25 insertions, 93 deletions
diff --git a/src/library/scala/xml/Utility.scala b/src/library/scala/xml/Utility.scala
index bba4d926c1..0991033cac 100644
--- a/src/library/scala/xml/Utility.scala
+++ b/src/library/scala/xml/Utility.scala
@@ -268,57 +268,6 @@ object Utility extends AnyRef with parsing.TokenTests {
}
)
- /**
- * Returns a hashcode for the given constituents of a node
- *
- * @param uri
- * @param label
- * @param attribs
- * @param children
- def hashCode(uri: String, label: String, attribs: scala.collection.mutable.HashMap[(String,String),String], scpe: Int, children: Seq[Node]): Int = {
- 41 * uri.hashCode() % 7 + label.hashCode() + attribs.toList.hashCode() + scpe + children.hashCode()
- }
- */
-
- /**
- * @param s ...
- * @return ...
- */
- def systemLiteralToString(s: String): String = {
- val sb = new StringBuilder()
- systemLiteralToString(sb, s)
- sb.toString()
- }
-
- /**
- * @param sb ...
- * @param s ...
- * @return ...
- */
- def systemLiteralToString(sb: StringBuilder, s: String): StringBuilder = {
- sb.append("SYSTEM ")
- appendQuoted(s, sb)
- }
-
- /**
- * @param s ...
- * @return ...
- */
- def publicLiteralToString(s: String): String = {
- val sb = new StringBuilder()
- publicLiteralToString(sb, s)
- sb.toString()
- }
-
- /**
- * @param sb ...
- * @param s ...
- * @return ...
- */
- def publicLiteralToString(sb: StringBuilder, s: String): StringBuilder = {
- sb.append("PUBLIC \"").append(s).append('"')
- }
-
def appendQuoted(s: String): String = {
val sb = new StringBuilder()
appendQuoted(s, sb)
diff --git a/src/library/scala/xml/dtd/ExternalID.scala b/src/library/scala/xml/dtd/ExternalID.scala
index fe2e20efbe..dc9c2e5afb 100644
--- a/src/library/scala/xml/dtd/ExternalID.scala
+++ b/src/library/scala/xml/dtd/ExternalID.scala
@@ -11,21 +11,30 @@
package scala.xml.dtd
-
/** an ExternalIDs - either PublicID or SystemID
*
* @author Burak Emir
*/
-abstract class ExternalID {
+abstract class ExternalID extends parsing.TokenTests
+{
+ def quoted(s: String) = {
+ val c = if (s contains '"') '\'' else '"'
+ c + s + c
+ }
- /** returns "PUBLIC "+publicLiteral+" SYSTEM "+systemLiteral */
- override def toString(): String
+ // public != null: PUBLIC " " publicLiteral " " [systemLiteral]
+ // public == null: SYSTEM " " systemLiteral
+ override def toString(): String = {
+ lazy val quotedSystemLiteral = quoted(systemId)
+ lazy val quotedPublicLiteral = quoted(publicId)
- /** returns "PUBLIC "+publicLiteral+" SYSTEM "+systemLiteral */
- def toString(sb: StringBuilder): StringBuilder
+ if (publicId == null) "SYSTEM " + quotedSystemLiteral
+ else "PUBLIC " + quotedPublicLiteral +
+ (if (systemId == null) "" else " " + quotedSystemLiteral)
+ }
def systemId: String
-
+ def publicId: String
}
/** a system identifier
@@ -33,18 +42,11 @@ abstract class ExternalID {
* @author Burak Emir
* @param systemLiteral the system identifier literal
*/
-case class SystemID(systemId: String) extends ExternalID with parsing.TokenTests {
-
- if( !checkSysID(systemId) )
- throw new IllegalArgumentException(
- "can't use both \" and ' in systemLiteral"
- )
- /** returns " SYSTEM "+systemLiteral */
- override def toString() =
- Utility.systemLiteralToString(systemId)
+case class SystemID(systemId: String) extends ExternalID {
+ val publicId = null
- override def toString(sb: StringBuilder): StringBuilder =
- Utility.systemLiteralToString(sb, systemId)
+ if (!checkSysID(systemId))
+ throw new IllegalArgumentException("can't use both \" and ' in systemId")
}
@@ -54,17 +56,12 @@ case class SystemID(systemId: String) extends ExternalID with parsing.TokenTests
* @param publicLiteral the public identifier literal
* @param systemLiteral (can be null for notation pubIDs) the system identifier literal
*/
-case class PublicID(publicId: String, systemId: String)
-extends ExternalID with parsing.TokenTests {
-
+case class PublicID(publicId: String, systemId: String) extends ExternalID {
if (!checkPubID(publicId))
- throw new IllegalArgumentException(
- "publicId must consist of PubidChars"
- )
- if ((systemId ne null) && !checkSysID(systemId))
- throw new IllegalArgumentException(
- "can't use both \" and ' in systemId"
- )
+ throw new IllegalArgumentException("publicId must consist of PubidChars")
+
+ if (systemId != null && !checkSysID(systemId))
+ throw new IllegalArgumentException("can't use both \" and ' in systemId")
/** the constant "#PI" */
def label = "#PI"
@@ -74,18 +71,4 @@ extends ExternalID with parsing.TokenTests {
/** always empty */
def child = Nil
-
- /** returns " PUBLIC "+publicId+" "+systemId */
- override def toString() =
- toString(new StringBuilder()).toString()
-
- /** appends "PUBLIC "+publicId+" "+systemId to argument */
- override def toString(sb: StringBuilder): StringBuilder = {
- Utility.publicLiteralToString(sb, publicId)
- if (systemId ne null) {
- sb.append(' ')
- Utility.appendQuoted(systemId, sb)
- }
- sb
- }
}