Repository: groovy Updated Branches: refs/heads/GROOVY_2_6_X 42986d65c -> 2359b538e
Minor refactoring (cherry picked from commit e0b473c) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/2359b538 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/2359b538 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/2359b538 Branch: refs/heads/GROOVY_2_6_X Commit: 2359b538ed8ed6fe043f24e3f454b575a068479f Parents: 42986d6 Author: sunlan <[email protected]> Authored: Tue Nov 7 07:58:36 2017 +0800 Committer: sunlan <[email protected]> Committed: Tue Nov 7 07:59:47 2017 +0800 ---------------------------------------------------------------------- .../apache/groovy/parser/antlr4/AstBuilder.java | 28 +++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/2359b538/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 40bbdb0..f176b25 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 @@ -3345,35 +3345,37 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov } private String parseGStringEnd(GstringContext ctx, String beginQuotation) { - String text = ctx.GStringEnd().getText(); - text = beginQuotation + text; + StringBuilder text = new StringBuilder(ctx.GStringEnd().getText()); + text.insert(0, beginQuotation); - return this.parseStringLiteral(text); + return this.parseStringLiteral(text.toString()); } private String parseGStringPart(TerminalNode e, String beginQuotation) { - String text = e.getText(); - text = text.substring(0, text.length() - 1); // remove the tailing $ - text = beginQuotation + text + QUOTATION_MAP.get(beginQuotation); + StringBuilder text = new StringBuilder(e.getText()); + text.deleteCharAt(text.length() - 1); // remove the tailing $ + text.insert(0, beginQuotation).append(QUOTATION_MAP.get(beginQuotation)); - return this.parseStringLiteral(text); + return this.parseStringLiteral(text.toString()); } private String parseGStringBegin(GstringContext ctx, String beginQuotation) { - String text = ctx.GStringBegin().getText(); - text = text.substring(0, text.length() - 1); // remove the tailing $ - text = text + QUOTATION_MAP.get(beginQuotation); + StringBuilder text = new StringBuilder(ctx.GStringBegin().getText()); + text.deleteCharAt(text.length() - 1); // remove the tailing $ + text.append(QUOTATION_MAP.get(beginQuotation)); - return this.parseStringLiteral(text); + return this.parseStringLiteral(text.toString()); } private String beginQuotation(String text) { if (text.startsWith(TDQ_STR)) { return TDQ_STR; - } else if (text.startsWith(DOLLAR_SLASH_STR)) { - return DOLLAR_SLASH_STR; + } else if (text.startsWith(DQ_STR)) { + return DQ_STR; } else if (text.startsWith(SLASH_STR)) { return SLASH_STR; + } else if (text.startsWith(DOLLAR_SLASH_STR)) { + return DOLLAR_SLASH_STR; } else { return String.valueOf(text.charAt(0)); }
