diff options
author | dcaoyuan <dcaoyuan@epfl.ch> | 2010-04-19 15:16:53 +0000 |
---|---|---|
committer | dcaoyuan <dcaoyuan@epfl.ch> | 2010-04-19 15:16:53 +0000 |
commit | 199f6f6cb8b5915a8902907905d6755dc4237061 (patch) | |
tree | a1ddefb4028b68402fbf638f93807adeafd187e7 /src | |
parent | 41c280194dd92025c3291b977549dd174b108ec9 (diff) | |
download | scala-199f6f6cb8b5915a8902907905d6755dc4237061.tar.gz scala-199f6f6cb8b5915a8902907905d6755dc4237061.tar.bz2 scala-199f6f6cb8b5915a8902907905d6755dc4237061.zip |
Fixed #3322wq
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/xml/Utility.scala | 25 | ||||
-rw-r--r-- | src/library/scala/xml/Xhtml.scala | 10 |
2 files changed, 20 insertions, 15 deletions
diff --git a/src/library/scala/xml/Utility.scala b/src/library/scala/xml/Utility.scala index 48a23dc389..8637148489 100644 --- a/src/library/scala/xml/Utility.scala +++ b/src/library/scala/xml/Utility.scala @@ -194,22 +194,24 @@ object Utility extends AnyRef with parsing.TokenTests minimizeTags: Boolean = false): StringBuilder = { x match { - case c: Comment if !stripComments => c buildString sb - case x: SpecialNode => x buildString sb - case g: Group => for (c <- g.nodes) toXML(c, x.scope, sb) ; sb + case c: Comment => if (!stripComments) c buildString sb else sb + case x: SpecialNode => x buildString sb + case g: Group => + g.nodes foreach {toXML(_, x.scope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags)} + sb case _ => // print tag with namespace declarations sb.append('<') x.nameToString(sb) if (x.attributes ne null) x.attributes.buildString(sb) x.scope.buildString(sb, pscope) - if (x.child.isEmpty && minimizeTags) + if (x.child.isEmpty && minimizeTags) { // no children, so use short form: <xyz .../> sb.append(" />") - else { + } else { // children, so use long form: <xyz ...>...</xyz> sb.append('>') - sequenceToXML(x.child, x.scope, sb, stripComments) + sequenceToXML(x.child, x.scope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags) sb.append("</") x.nameToString(sb) sb.append('>') @@ -221,20 +223,23 @@ object Utility extends AnyRef with parsing.TokenTests children: Seq[Node], pscope: NamespaceBinding = TopScope, sb: StringBuilder = new StringBuilder, - stripComments: Boolean = false): Unit = + stripComments: Boolean = false, + decodeEntities: Boolean = true, + preserveWhitespace: Boolean = false, + minimizeTags: Boolean = false): Unit = { if (children.isEmpty) return else if (children forall isAtomAndNotText) { // add space val it = children.iterator val f = it.next - toXML(f, pscope, sb) + toXML(f, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags) while (it.hasNext) { val x = it.next sb.append(' ') - toXML(x, pscope, sb) + toXML(x, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags) } } - else children foreach { toXML(_, pscope, sb) } + else children foreach { toXML(_, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags) } } /** diff --git a/src/library/scala/xml/Xhtml.scala b/src/library/scala/xml/Xhtml.scala index 744fe260c2..162ea5696a 100644 --- a/src/library/scala/xml/Xhtml.scala +++ b/src/library/scala/xml/Xhtml.scala @@ -49,11 +49,11 @@ object Xhtml (minimizableElements contains x.label) x match { - case c: Comment if !stripComments => c buildString sb + case c: Comment => if (!stripComments) c buildString sb case er: EntityRef if decodeEntities => decode(er) case x: SpecialNode => x buildString sb case g: Group => - g.nodes foreach { toXhtml(_, x.scope, sb) } + g.nodes foreach { toXhtml(_, x.scope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags) } case _ => sb.append('<') @@ -64,7 +64,7 @@ object Xhtml if (shortForm) sb.append(" />") else { sb.append('>') - sequenceToXML(x.child, x.scope, sb) + sequenceToXML(x.child, x.scope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags) sb.append("</") x.nameToString(sb) sb.append('>') @@ -89,9 +89,9 @@ object Xhtml val doSpaces = children forall isAtomAndNotText // interleave spaces for (c <- children.take(children.length - 1)) { - toXhtml(c, pscope, sb) + toXhtml(c, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags) if (doSpaces) sb append ' ' } - toXhtml(children.last, pscope, sb) + toXhtml(children.last, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags) } } |