parent
3b25c864f8
commit
2b969e2fdc
|
@ -4,6 +4,7 @@ import com.rusefi.EnumsReader;
|
||||||
import com.rusefi.ReaderState;
|
import com.rusefi.ReaderState;
|
||||||
import com.rusefi.ReaderStateImpl;
|
import com.rusefi.ReaderStateImpl;
|
||||||
import com.rusefi.VariableRegistry;
|
import com.rusefi.VariableRegistry;
|
||||||
|
import com.rusefi.enum_reader.Value;
|
||||||
import com.rusefi.newparse.ParseState;
|
import com.rusefi.newparse.ParseState;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -101,7 +102,7 @@ public class PinoutLogicIntegratedTest {
|
||||||
state.getEnumsReader().read(new StringReader("enum class Gpio : uint16_t {\n" +
|
state.getEnumsReader().read(new StringReader("enum class Gpio : uint16_t {\n" +
|
||||||
"Unassigned = 0,\n" +
|
"Unassigned = 0,\n" +
|
||||||
"Invalid = 0x01,\n" +
|
"Invalid = 0x01,\n" +
|
||||||
"E11 = 2,\n" +
|
"E11 = 0x0B,\n" +
|
||||||
"};"));
|
"};"));
|
||||||
|
|
||||||
ParseState definitionState = new ParseState(state.getEnumsReader());
|
ParseState definitionState = new ParseState(state.getEnumsReader());
|
||||||
|
@ -112,4 +113,14 @@ public class PinoutLogicIntegratedTest {
|
||||||
|
|
||||||
assertEquals(expected, testWriter.getBuffer().toString());
|
assertEquals(expected, testWriter.getBuffer().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parseInt() {
|
||||||
|
assertEquals(1, Value.parseInt("1"));
|
||||||
|
assertEquals(10, Value.parseInt("0x0a"));
|
||||||
|
assertEquals(10, Value.parseInt("0xa"));
|
||||||
|
assertEquals(10, Value.parseInt("0Xa"));
|
||||||
|
assertEquals(11, Value.parseInt("0x0B"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -29,9 +29,14 @@ public class Value implements Comparable<Value> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getIntValue() {
|
public int getIntValue() {
|
||||||
if (value.toLowerCase().startsWith("0x"))
|
return parseInt(value);
|
||||||
return Integer.parseInt(value.substring(2), 16);
|
}
|
||||||
return Integer.parseInt(value);
|
|
||||||
|
public static int parseInt(String value) {
|
||||||
|
String trimmed = value.trim();
|
||||||
|
if (trimmed.toLowerCase().startsWith("0x"))
|
||||||
|
return Integer.parseInt(trimmed.substring(2), 16);
|
||||||
|
return Integer.parseInt(trimmed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,9 +56,13 @@ public class Value implements Comparable<Value> {
|
||||||
try {
|
try {
|
||||||
return getIntValue();
|
return getIntValue();
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
String resolvedValue = registry.get(value);
|
return handleNotInteger(registry);
|
||||||
Objects.requireNonNull(resolvedValue, value);
|
|
||||||
return Integer.parseInt(resolvedValue);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int handleNotInteger(VariableRegistry registry) {
|
||||||
|
String resolvedValue = registry.get(value);
|
||||||
|
Objects.requireNonNull(resolvedValue, value);
|
||||||
|
return Integer.parseInt(resolvedValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue