REO progress

This commit is contained in:
rusefi 2020-06-13 23:32:46 -04:00
parent e1ca5f50e8
commit 395ace2d3a
2 changed files with 15 additions and 4 deletions

View File

@ -20,7 +20,7 @@ public class IniFileReader {
* {x, y, "Z"} * {x, y, "Z"}
* array of Strings * array of Strings
* *
* equals sign, space, tab and commas are all equally considered not parts of the token, quotes are supportd * equals sign, space, tab and commas are all equally considered not parts of the token, quotes are supported
* *
* Technically a line like * Technically a line like
* x, y = z * x, y = z
@ -31,15 +31,25 @@ public class IniFileReader {
public static String[] splitTokens(String str) { public static String[] splitTokens(String str) {
ArrayList<String> strings = new ArrayList<>(); ArrayList<String> strings = new ArrayList<>();
boolean inQuote = false; boolean inQuote = false;
boolean hadQuote = false;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < str.length(); i++) { for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i); char c = str.charAt(i);
if (c == '\"' || isTokenSeparator(c) && !inQuote) { if (c == '\"' || isTokenSeparator(c) && !inQuote) {
if (c == '\"') if (c == '\"') {
inQuote = !inQuote; inQuote = !inQuote;
if (!inQuote) {
// we are here when we close quotes
hadQuote = true;
}
}
if (!inQuote && sb.length() > 0) { if (!inQuote && sb.length() > 0) {
strings.add(sb.toString()); strings.add(sb.toString());
sb.delete(0, sb.length()); sb.delete(0, sb.length());
hadQuote = false;
} else if (hadQuote) {
strings.add("");
hadQuote = false;
} }
} else } else
sb.append(c); sb.append(c);

View File

@ -25,11 +25,12 @@ public class IniFileReaderTest {
public void testSplitWithEmptyUnits() { public void testSplitWithEmptyUnits() {
{ {
String[] s = IniFileReader.splitTokens("\tverboseCanBaseAddress\t\t\t= \"\", 1"); String[] s = IniFileReader.splitTokens("\tverboseCanBaseAddress\t\t\t= \"\", 1");
assertEquals(2, s.length); assertEquals(3, s.length);
assertEquals("", s[1]);
} }
{ {
String[] s = IniFileReader.splitTokens("\tverboseCanBaseAddress\t\t\t= scalar, U32,\t756,\t\"\", 1, 0, 0, 536870911, 0"); String[] s = IniFileReader.splitTokens("\tverboseCanBaseAddress\t\t\t= scalar, U32,\t756,\t\"\", 1, 0, 0, 536870911, 0");
assertEquals(9, s.length); assertEquals(10, s.length);
} }
} }