This is an automated email from the ASF dual-hosted git repository. sunlan pushed a commit to branch GROOVY_3_0_X in repository https://gitbox.apache.org/repos/asf/groovy.git
commit b5107ecc4e90f03150b296312368f8f8a3b2c2b0 Author: Daniel Sun <[email protected]> AuthorDate: Sat Apr 11 22:25:51 2020 +0800 Trivial refactoring: extract common code further (cherry picked from commit 7b6c81bd551db8f766bed9181d281945a4686926) --- .../src/main/groovy/groovy/xml/StreamingMarkupBuilder.groovy | 8 +------- .../xml/streamingmarkupsupport/AbstractStreamingBuilder.groovy | 9 +++++---- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/subprojects/groovy-xml/src/main/groovy/groovy/xml/StreamingMarkupBuilder.groovy b/subprojects/groovy-xml/src/main/groovy/groovy/xml/StreamingMarkupBuilder.groovy index b5e0a2e..ee0f124 100644 --- a/subprojects/groovy-xml/src/main/groovy/groovy/xml/StreamingMarkupBuilder.groovy +++ b/subprojects/groovy-xml/src/main/groovy/groovy/xml/StreamingMarkupBuilder.groovy @@ -75,13 +75,7 @@ class StreamingMarkupBuilder extends AbstractStreamingBuilder { out.unescaped() << "<?" if (instruction instanceof Map) { out.unescaped() << target - instruction.each {name, value -> - if (value.toString().contains('\'') || (useDoubleQuotes && !value.toString().contains('"'))) { - out.unescaped() << " $name=\"$value\"" - } else { - out.unescaped() << " $name='$value'" - } - } + out.unescaped() << toMapString(instruction, {value -> value.toString().contains('\'') || (useDoubleQuotes && !value.toString().contains('"'))}) } else { out.unescaped() << "$target $instruction" } diff --git a/subprojects/groovy-xml/src/main/groovy/groovy/xml/streamingmarkupsupport/AbstractStreamingBuilder.groovy b/subprojects/groovy-xml/src/main/groovy/groovy/xml/streamingmarkupsupport/AbstractStreamingBuilder.groovy index 91a3057..a109e4a 100644 --- a/subprojects/groovy-xml/src/main/groovy/groovy/xml/streamingmarkupsupport/AbstractStreamingBuilder.groovy +++ b/subprojects/groovy-xml/src/main/groovy/groovy/xml/streamingmarkupsupport/AbstractStreamingBuilder.groovy @@ -62,13 +62,14 @@ class AbstractStreamingBuilder { } def getNamespaceClosure = {doc, pendingNamespaces, namespaces, Object[] rest -> [namespaces, pendingNamespaces]} - def toMapString = { Map instruction -> + def toMapString = { Map instruction, checkDoubleQutationMarks={value -> !value.toString().contains('"')} -> def buf = new StringBuilder() instruction.each { name, value -> - if (value.toString().contains('"')) - buf.append(" $name='$value'") - else + if (checkDoubleQutationMarks(value)) { buf.append(" $name=\"$value\"") + } else { + buf.append(" $name='$value'") + } } return buf.toString() }
