Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 7347ea620 -> f14e2a1fc


Minor refactoring

(cherry picked from commit 4ca7598)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/f14e2a1f
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/f14e2a1f
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/f14e2a1f

Branch: refs/heads/GROOVY_2_6_X
Commit: f14e2a1fc25be788611893988987fb04c51f9982
Parents: 7347ea6
Author: sunlan <[email protected]>
Authored: Thu Aug 17 08:06:38 2017 +0800
Committer: sunlan <[email protected]>
Committed: Thu Aug 17 08:07:29 2017 +0800

----------------------------------------------------------------------
 .../main/java/org/apache/groovy/parser/antlr4/AstBuilder.java | 6 +++---
 .../org/apache/groovy/parser/antlr4/util/StringUtils.java     | 7 ++++++-
 2 files changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/f14e2a1f/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
----------------------------------------------------------------------
diff --git 
a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
 
b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index 67ca907..766e998 100644
--- 
a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ 
b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -2378,17 +2378,17 @@ public class AstBuilder extends 
GroovyParserBaseVisitor<Object> implements Groov
         if (text.startsWith("'''") || text.startsWith("\"\"\"")) {
             text = StringUtils.removeCR(text); // remove CR in the multiline 
string
 
-            text = text.length() == 6 ? "" : text.substring(3, text.length() - 
3);
+            text = StringUtils.trimQuotations(text, 3);
         } else if (text.startsWith("'") || text.startsWith("/") || 
text.startsWith("\"")) {
             if (text.startsWith("/")) { // the slashy string can span rows, so 
we have to remove CR for it
                 text = StringUtils.removeCR(text); // remove CR in the 
multiline string
             }
 
-            text = text.length() == 2 ? "" : text.substring(1, text.length() - 
1);
+            text = StringUtils.trimQuotations(text, 1);
         } else if (text.startsWith("$/")) {
             text = StringUtils.removeCR(text);
 
-            text = text.length() == 4 ? "" : text.substring(2, text.length() - 
2);
+            text = StringUtils.trimQuotations(text, 2);
         }
 
         //handle escapes.

http://git-wip-us.apache.org/repos/asf/groovy/blob/f14e2a1f/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/StringUtils.java
----------------------------------------------------------------------
diff --git 
a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/StringUtils.java
 
b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/StringUtils.java
index 1a37cdf..5aad139 100644
--- 
a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/StringUtils.java
+++ 
b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/StringUtils.java
@@ -22,7 +22,6 @@ import groovy.lang.Closure;
 import org.apache.groovy.util.Maps;
 import org.codehaus.groovy.runtime.StringGroovyMethods;
 
-import java.util.HashMap;
 import java.util.Map;
 import java.util.regex.Pattern;
 
@@ -150,4 +149,10 @@ public class StringUtils {
                }
                return count; // return text.chars().filter(e -> c == 
e).count();
        }
+
+       public static String trimQuotations(String text, int quotationLength) {
+               int length = text.length();
+
+               return length == quotationLength * 2 ? "" : 
text.substring(quotationLength, length - quotationLength);
+       }
 }
\ No newline at end of file

Reply via email to