Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellansun committed Aug 17, 2017
1 parent a52f77a commit 4ca7598
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2350,17 +2350,17 @@ public ConstantExpression visitStringLiteral(StringLiteralContext ctx) {
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
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;

Expand Down Expand Up @@ -145,4 +144,10 @@ public static String removeCR(String text) {
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);
}
}

0 comments on commit 4ca7598

Please sign in to comment.