diff options
author | Paul Phillips <paulp@improving.org> | 2009-09-23 03:02:21 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-09-23 03:02:21 +0000 |
commit | 2fe29c477aebdd77c3faaa7d0fb77d7247efc556 (patch) | |
tree | cbfa7746d098061413dba602e259c721e1b24df9 | |
parent | e5464bcb42ee86cbd57c37c0a7963e3b8d6d4d0c (diff) | |
download | scala-2fe29c477aebdd77c3faaa7d0fb77d7247efc556.tar.gz scala-2fe29c477aebdd77c3faaa7d0fb77d7247efc556.tar.bz2 scala-2fe29c477aebdd77c3faaa7d0fb77d7247efc556.zip |
Fix for #2374.
-rw-r--r-- | src/library/scala/xml/NamespaceBinding.scala | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/src/library/scala/xml/NamespaceBinding.scala b/src/library/scala/xml/NamespaceBinding.scala index 7588663f7f..b0ea5dcc84 100644 --- a/src/library/scala/xml/NamespaceBinding.scala +++ b/src/library/scala/xml/NamespaceBinding.scala @@ -25,37 +25,31 @@ import Utility.sbToString @SerialVersionUID(0 - 2518644165573446725L) case class NamespaceBinding(prefix: String, uri: String, parent: NamespaceBinding) extends AnyRef { - if (null != prefix && 0 == prefix.length()) + if (prefix != null && prefix.isEmpty) throw new IllegalArgumentException("zero length prefix not allowed") def getURI(_prefix: String): String = - if (prefix == _prefix) uri - else parent getURI _prefix + if (prefix == _prefix) uri else parent getURI _prefix - /** Returns some prefix that is mapped to the prefix. + /** Returns some prefix that is mapped to the URI. * - * @param _uri - * @return + * @param _uri the input URI + * @return the prefix that is mapped to the input URI, or null + * if no prefix is mapped to the URI. */ def getPrefix(_uri: String): String = - if (_uri == uri) uri - else parent getURI _uri + if (_uri == uri) prefix else parent getPrefix _uri override def toString(): String = sbToString(buildString(_, TopScope)) def buildString(stop: NamespaceBinding): String = sbToString(buildString(_, stop)) def buildString(sb: StringBuilder, stop: NamespaceBinding): Unit = { - if (this ne stop) { // contains? - sb.append(" xmlns") - if (prefix ne null) { - sb.append(':').append(prefix) - } - sb.append('=') - .append('"') - .append(if (uri == null) "" else uri) - .append('"'); - parent.buildString(sb, stop) // copy(ignore) - } - } + if (this eq stop) return // contains? + val s = " xmlns%s=\"%s\"".format( + (if (prefix != null) ":" + prefix else ""), + (if (uri != null) uri else "") + ) + parent.buildString(sb append s, stop) // copy(ignore) + } } |