diff --git a/java_tools/configuration_definition/src/test/java/com/rusefi/test/ConfigFieldParserTest.java b/java_tools/configuration_definition/src/test/java/com/rusefi/test/ConfigFieldParserTest.java index 42720c27ae..a9f802d814 100644 --- a/java_tools/configuration_definition/src/test/java/com/rusefi/test/ConfigFieldParserTest.java +++ b/java_tools/configuration_definition/src/test/java/com/rusefi/test/ConfigFieldParserTest.java @@ -70,7 +70,6 @@ public class ConfigFieldParserTest { } @Test - @Disabled public void testArrayBitStringValue() { String test = "struct pid_s\n" + "int[3 x 1] afr_type;;{bitStringValue(fuelUnits, fuelAlgorithm) }, 1.0, 0, 0, 3000, 0, noMsqSave\n" + @@ -79,7 +78,7 @@ public class ConfigFieldParserTest { TestTSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer("", state); state.readBufferedReader(test, tsProjectConsumer); - assertEquals("afr_type = array, S32, 0, [1x3], \"ms\", 1, 0, 0, 3000, 0, noMsqSave\n" + + assertEquals("afr_type = array, S32, 0, [1x3], {bitStringValue(fuelUnits, fuelAlgorithm) }, 1, 0, 0, 3000, 0, noMsqSave\n" + "; total TS size = 12\n", tsProjectConsumer.getContent()); } diff --git a/java_tools/configuration_definition_base/src/main/java/com/rusefi/ConfigFieldImpl.java b/java_tools/configuration_definition_base/src/main/java/com/rusefi/ConfigFieldImpl.java index df624e5017..2c9a0b287f 100644 --- a/java_tools/configuration_definition_base/src/main/java/com/rusefi/ConfigFieldImpl.java +++ b/java_tools/configuration_definition_base/src/main/java/com/rusefi/ConfigFieldImpl.java @@ -12,6 +12,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import static com.devexperts.logging.Logging.getLogging; +import static com.rusefi.TokenUtils.tokenizeWithBraces; import com.rusefi.parse.TypesHelper; import org.jetbrains.annotations.Nullable; @@ -373,9 +374,7 @@ public class ConfigFieldImpl implements ConfigField { } private String[] getTokens() { - if (tsInfo == null) - return new String[0]; - return tsInfo.split(","); + return tokenizeWithBraces(tsInfo); } @Override diff --git a/java_tools/configuration_definition_base/src/main/java/com/rusefi/TokenUtils.java b/java_tools/configuration_definition_base/src/main/java/com/rusefi/TokenUtils.java new file mode 100644 index 0000000000..cd042fd767 --- /dev/null +++ b/java_tools/configuration_definition_base/src/main/java/com/rusefi/TokenUtils.java @@ -0,0 +1,42 @@ +package com.rusefi; + +import java.util.ArrayList; +import java.util.List; + +public class TokenUtils { + public static String[] tokenizeWithBraces(String stringToTokenize) { + final List tokens = new ArrayList<>(); + if (stringToTokenize != null) { + StringBuilder currentToken = new StringBuilder(); + int openedBracesCount = 0; + for (char ch : stringToTokenize.toCharArray()) { + // we finish token parsing only if it contains no unclosed braces + if ((ch == ',') && (openedBracesCount == 0)) { + tokens.add(currentToken.toString()); + currentToken.setLength(0); + } else { + currentToken.append(ch); + switch (ch) { + case '{': { + openedBracesCount++; + break; + } + case '}': { + if (0 < openedBracesCount) { + openedBracesCount--; + } else { + throw new IllegalStateException("Unexpected closing brace"); + } + break; + } + } + } + } + if (openedBracesCount != 0) { + throw new IllegalStateException("Unclosed opening brace"); + } + tokens.add(currentToken.toString()); + } + return tokens.toArray(String[]::new); + } +} diff --git a/java_tools/configuration_definition_base/src/main/java/com/rusefi/output/TsOutput.java b/java_tools/configuration_definition_base/src/main/java/com/rusefi/output/TsOutput.java index 915abbefcc..68734ef5b2 100644 --- a/java_tools/configuration_definition_base/src/main/java/com/rusefi/output/TsOutput.java +++ b/java_tools/configuration_definition_base/src/main/java/com/rusefi/output/TsOutput.java @@ -13,6 +13,7 @@ import java.util.List; import java.util.TreeSet; import java.util.stream.Collectors; +import static com.rusefi.TokenUtils.tokenizeWithBraces; import static com.rusefi.ToolUtil.EOL; import static com.rusefi.output.JavaSensorsConsumer.quote; @@ -164,7 +165,7 @@ public class TsOutput { return quote("") + ", 1, 0"; } try { - String[] fields = tsInfo.split(","); + String[] fields = tokenizeWithBraces(tsInfo); if (fields.length > multiplierIndex) { /** * Evaluate static math on .ini layer to simplify rusEFI java and rusEFI PHP project consumers