From ee8110e7312effe55f1d5ddaf5bed05c3392976b Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 17 Jul 2013 14:36:20 +0200 Subject: [PATCH] Updated StringReplacer.quotedSplit() to accept more than one quote char. --- .../app/helpers/StringReplacer.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/app/src/processing/app/helpers/StringReplacer.java b/app/src/processing/app/helpers/StringReplacer.java index c6b02a23b..2ab42896a 100644 --- a/app/src/processing/app/helpers/StringReplacer.java +++ b/app/src/processing/app/helpers/StringReplacer.java @@ -34,7 +34,7 @@ public class StringReplacer { String res; // Recursive replace with a max depth of 10 levels. - for (int i=0; i<10; i++) { + for (int i = 0; i < 10; i++) { // Do a replace with dictionary res = StringReplacer.replaceFromMapping(src, dict); if (!recursive) @@ -45,30 +45,31 @@ public class StringReplacer { } // Split the resulting string in arguments - return quotedSplit(src, '"', false); + return quotedSplit(src, "\"'", false); } - public static String[] quotedSplit(String src, char escapeChar, + public static String[] quotedSplit(String src, String quoteChars, boolean acceptEmptyArguments) throws Exception { - String quote = "" + escapeChar; List res = new ArrayList(); String escapedArg = null; - boolean escaping = false; + String escapingChar = null; for (String i : src.split(" ")) { - if (!escaping) { - if (!i.startsWith(quote)) { + if (escapingChar == null) { + // If the first char is not an escape char.. + String first = i.substring(0, 1); + if (!quoteChars.contains(first)) { if (i.trim().length() != 0 || acceptEmptyArguments) res.add(i); continue; } - escaping = true; + escapingChar = first; i = i.substring(1); escapedArg = ""; } - if (!i.endsWith(quote)) { + if (!i.endsWith(escapingChar)) { escapedArg += i + " "; continue; } @@ -76,11 +77,11 @@ public class StringReplacer { escapedArg += i.substring(0, i.length() - 1); if (escapedArg.trim().length() != 0 || acceptEmptyArguments) res.add(escapedArg); - escaping = false; + escapingChar = null; } - if (escaping) - throw new Exception("Invalid quoting: no closing '" + escapeChar + - "' char found."); + if (escapingChar != null) + throw new Exception("Invalid quoting: no closing [" + escapingChar + + "] char found."); return res.toArray(new String[0]); }