diff --git a/java_console/inifile/src/com/opensr5/ini/IniFileReader.java b/java_console/inifile/src/com/opensr5/ini/IniFileReader.java index 97553356b8..48e99baf03 100644 --- a/java_console/inifile/src/com/opensr5/ini/IniFileReader.java +++ b/java_console/inifile/src/com/opensr5/ini/IniFileReader.java @@ -20,7 +20,7 @@ public class IniFileReader { * {x, y, "Z"} * 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 * x, y = z @@ -31,15 +31,25 @@ public class IniFileReader { public static String[] splitTokens(String str) { ArrayList strings = new ArrayList<>(); boolean inQuote = false; + boolean hadQuote = false; StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c == '\"' || isTokenSeparator(c) && !inQuote) { - if (c == '\"') + if (c == '\"') { inQuote = !inQuote; + if (!inQuote) { + // we are here when we close quotes + hadQuote = true; + } + } if (!inQuote && sb.length() > 0) { strings.add(sb.toString()); sb.delete(0, sb.length()); + hadQuote = false; + } else if (hadQuote) { + strings.add(""); + hadQuote = false; } } else sb.append(c); diff --git a/java_console/inifile/src/com/opensr5/ini/test/IniFileReaderTest.java b/java_console/inifile/src/com/opensr5/ini/test/IniFileReaderTest.java index 946e3959a2..483161218f 100644 --- a/java_console/inifile/src/com/opensr5/ini/test/IniFileReaderTest.java +++ b/java_console/inifile/src/com/opensr5/ini/test/IniFileReaderTest.java @@ -25,11 +25,12 @@ public class IniFileReaderTest { public void testSplitWithEmptyUnits() { { 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"); - assertEquals(9, s.length); + assertEquals(10, s.length); } }