only:Improve toolset for default tune canned tune generation #4871
This commit is contained in:
parent
b46c7b0bcf
commit
c0cef2265a
|
@ -3,6 +3,7 @@ package com.rusefi.tune;
|
|||
import com.opensr5.ini.DialogModel;
|
||||
import com.opensr5.ini.IniFileModel;
|
||||
import com.rusefi.core.preferences.storage.Node;
|
||||
import com.rusefi.tools.tune.TuneTools;
|
||||
import com.rusefi.tune.xml.Constant;
|
||||
import com.rusefi.tune.xml.Msq;
|
||||
import com.rusefi.tune.xml.Page;
|
||||
|
@ -63,4 +64,19 @@ public class LoadOlderTuneTest {
|
|||
return value;
|
||||
return value.replaceAll("\\s+", " ").trim();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testLegacyCustomEnumOrdinal() {
|
||||
String tsCustomLine = "bits, U08, @OFFSET@, [0:1], \"Single Coil\", \"Individual Coils\", \"Wasted Spark\", \"Two Distributors\"";
|
||||
|
||||
assertEquals(0, TuneTools.resolveEnumByName(tsCustomLine, "One coil"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEnumOrdinal() {
|
||||
String tsCustomLine = "bits, U08, @OFFSET@, [0:1], \"Single Coil\", \"Individual Coils\", \"Wasted Spark\", \"Two Distributors\"";
|
||||
|
||||
assertEquals(0, TuneTools.resolveEnumByName(tsCustomLine, "Single coil"));
|
||||
assertEquals(3, TuneTools.resolveEnumByName(tsCustomLine, "Two Distributors"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package com.rusefi.tools.tune;
|
||||
|
||||
public class TuneTools {
|
||||
private static String quote(String string) {
|
||||
return "\"" + string + "\"";
|
||||
}
|
||||
|
||||
public static int resolveEnumByName(String tsCustomLine, String key) {
|
||||
String quotedKey = quote(key);
|
||||
String[] tokens = tsCustomLine.split(",");
|
||||
int magicOffset = 4; // skipping meta info header
|
||||
for (int i = 0; i < tokens.length - magicOffset; i++) {
|
||||
String token = tokens[i + magicOffset].trim();
|
||||
if (token.equalsIgnoreCase(quotedKey))
|
||||
return i;
|
||||
}
|
||||
throw new IllegalStateException("Enum name [" + key + "] not found in " + tsCustomLine);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue