REO progress
This commit is contained in:
parent
e1ca5f50e8
commit
395ace2d3a
|
@ -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<String> 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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue