From 4d3c8ef4be9990124a02082789b809d8814b09ab Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 30 Apr 2009 16:36:40 +0000 Subject: Two minor findbugs-discovered logic errors I've... Two minor findbugs-discovered logic errors I've had in storage until I had xml write access. --- src/library/scala/xml/PrettyPrinter.scala | 9 +++++---- src/library/scala/xml/dtd/ElementValidator.scala | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'src/library') diff --git a/src/library/scala/xml/PrettyPrinter.scala b/src/library/scala/xml/PrettyPrinter.scala index 2b8c50088e..56e3a2db1b 100644 --- a/src/library/scala/xml/PrettyPrinter.scala +++ b/src/library/scala/xml/PrettyPrinter.scala @@ -153,6 +153,9 @@ class PrettyPrinter( width:Int, step:Int ) { protected def fits(test: String) = test.length < width - cur + private def doPreserve(node: Node) = + node.attribute(XML.namespace, XML.space).map(_.toString == XML.preserve) getOrElse false + /** @param tail: what we'd like to sqeeze in */ protected def traverse(node: Node, pscope: NamespaceBinding, ind: Int): Unit = node match { @@ -166,10 +169,8 @@ class PrettyPrinter( width:Int, step:Int ) { val test = { val sb = new StringBuilder() Utility.toXML(node, pscope, sb, false) - if (node.attribute("http://www.w3.org/XML/1998/namespace", "space") == "preserve") - sb.toString() - else - TextBuffer.fromString(sb.toString()).toText(0)._data + if (doPreserve(node)) sb.toString + else TextBuffer.fromString(sb.toString()).toText(0)._data } if (childrenAreLeaves(node) && fits(test)) { makeBox(ind, test) diff --git a/src/library/scala/xml/dtd/ElementValidator.scala b/src/library/scala/xml/dtd/ElementValidator.scala index bbee01aa97..de969cab64 100644 --- a/src/library/scala/xml/dtd/ElementValidator.scala +++ b/src/library/scala/xml/dtd/ElementValidator.scala @@ -88,7 +88,7 @@ class ElementValidator() extends Function1[Node,Boolean] { //Console.println("exc"); exc = fromUndefinedAttribute( attr.key ) :: exc; - case AttrDecl(_, tpe, DEFAULT(true, fixedValue)) if(attr.value != fixedValue) => + case AttrDecl(_, tpe, DEFAULT(true, fixedValue)) if attr.value.toString != fixedValue => exc = fromFixedAttribute( attr.key, fixedValue, attr.value.toString) :: exc; case s => -- cgit v1.2.3