Repository: groovy Updated Branches: refs/heads/master a52f77a59 -> 4ca7598fa
Minor refactoring Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/4ca7598f Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/4ca7598f Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/4ca7598f Branch: refs/heads/master Commit: 4ca7598faa2c691abbce0aee1eed6457c10855df Parents: a52f77a Author: sunlan <[email protected]> Authored: Thu Aug 17 08:06:38 2017 +0800 Committer: sunlan <[email protected]> Committed: Thu Aug 17 08:06:38 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/4ca7598f/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 9ae615e..b596511 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 @@ -2350,17 +2350,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/4ca7598f/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 58ac588..e200742 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; @@ -145,4 +144,10 @@ public class StringUtils { public static long countChar(String text, char c) { 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
