You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/04/11 14:26:16 UTC

[groovy] branch master updated: Trivial refactoring: extract common code further

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 7b6c81b  Trivial refactoring: extract common code further
7b6c81b is described below

commit 7b6c81bd551db8f766bed9181d281945a4686926
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Apr 11 22:25:51 2020 +0800

    Trivial refactoring: extract common code further
---
 .../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()
     }