mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Merge branch 'ide-1.5.x' into dev-ide-1.5.x-discovery
Conflicts: hardware/arduino/avr/cores/arduino/USBCore.cpp
This commit is contained in:
@ -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,33 @@ 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<String> res = new ArrayList<String>();
|
||||
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 = null;
|
||||
if (i.length() > 0)
|
||||
first = i.substring(0, 1);
|
||||
if (first == null || !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 +79,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]);
|
||||
}
|
||||
|
||||
|
29
app/test/processing/app/helpers/StringReplacerTest.java
Normal file
29
app/test/processing/app/helpers/StringReplacerTest.java
Normal file
@ -0,0 +1,29 @@
|
||||
package processing.app.helpers;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class StringReplacerTest {
|
||||
|
||||
@Test
|
||||
public void quotingCheck() throws Exception {
|
||||
String in = "a\"bc ab'c 'abc abc' ";
|
||||
in += "\"abc abc\" '\"abc abc\"' ";
|
||||
in += "\"'abc abc'\"";
|
||||
String[] res = StringReplacer.quotedSplit(in, "\"'", false);
|
||||
assertArrayEquals(res, new String[] { "a\"bc", "ab'c", "abc abc",
|
||||
"abc abc", "\"abc abc\"", "'abc abc'" });
|
||||
}
|
||||
|
||||
@Test
|
||||
public void quotingCheckWithEmptyStringsAccepted() throws Exception {
|
||||
String in = "a\"bc ab'c 'abc abc' ";
|
||||
in += "\"abc abc\" '\"abc abc\"' ";
|
||||
in += "\"'abc abc'\"";
|
||||
String[] res = StringReplacer.quotedSplit(in, "\"'", true);
|
||||
assertArrayEquals(res, new String[] { "a\"bc", "ab'c", "", "", "abc abc",
|
||||
"abc abc", "\"abc abc\"", "'abc abc'" });
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user