Skip to content

Commit ee8110e

Browse files
committed
Updated StringReplacer.quotedSplit() to accept more than one quote char.
1 parent c70cba8 commit ee8110e

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

app/src/processing/app/helpers/StringReplacer.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static String[] formatAndSplit(String src, Map<String, String> dict,
3434
String res;
3535

3636
// Recursive replace with a max depth of 10 levels.
37-
for (int i=0; i<10; i++) {
37+
for (int i = 0; i < 10; i++) {
3838
// Do a replace with dictionary
3939
res = StringReplacer.replaceFromMapping(src, dict);
4040
if (!recursive)
@@ -45,42 +45,43 @@ public static String[] formatAndSplit(String src, Map<String, String> dict,
4545
}
4646

4747
// Split the resulting string in arguments
48-
return quotedSplit(src, '"', false);
48+
return quotedSplit(src, "\"'", false);
4949
}
5050

51-
public static String[] quotedSplit(String src, char escapeChar,
51+
public static String[] quotedSplit(String src, String quoteChars,
5252
boolean acceptEmptyArguments)
5353
throws Exception {
54-
String quote = "" + escapeChar;
5554
List<String> res = new ArrayList<String>();
5655
String escapedArg = null;
57-
boolean escaping = false;
56+
String escapingChar = null;
5857
for (String i : src.split(" ")) {
59-
if (!escaping) {
60-
if (!i.startsWith(quote)) {
58+
if (escapingChar == null) {
59+
// If the first char is not an escape char..
60+
String first = i.substring(0, 1);
61+
if (!quoteChars.contains(first)) {
6162
if (i.trim().length() != 0 || acceptEmptyArguments)
6263
res.add(i);
6364
continue;
6465
}
6566

66-
escaping = true;
67+
escapingChar = first;
6768
i = i.substring(1);
6869
escapedArg = "";
6970
}
7071

71-
if (!i.endsWith(quote)) {
72+
if (!i.endsWith(escapingChar)) {
7273
escapedArg += i + " ";
7374
continue;
7475
}
7576

7677
escapedArg += i.substring(0, i.length() - 1);
7778
if (escapedArg.trim().length() != 0 || acceptEmptyArguments)
7879
res.add(escapedArg);
79-
escaping = false;
80+
escapingChar = null;
8081
}
81-
if (escaping)
82-
throw new Exception("Invalid quoting: no closing '" + escapeChar +
83-
"' char found.");
82+
if (escapingChar != null)
83+
throw new Exception("Invalid quoting: no closing [" + escapingChar +
84+
"] char found.");
8485
return res.toArray(new String[0]);
8586
}
8687

0 commit comments

Comments
 (0)