This commit is contained in:
parent
005307c3d1
commit
a42569382c
|
@ -24,6 +24,8 @@ public class VariableRegistry {
|
||||||
private final TreeMap<String, String> data = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
private final TreeMap<String, String> data = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
public static final VariableRegistry INSTANCE = new VariableRegistry();
|
public static final VariableRegistry INSTANCE = new VariableRegistry();
|
||||||
|
|
||||||
|
// todo: smarter regex! See TsWriter.VAR which is a bit better but still not perfect
|
||||||
|
// todo: https://github.com/rusefi/rusefi/issues/3053 ?
|
||||||
private final Pattern VAR = Pattern.compile("(@@(.*?)@@)");
|
private final Pattern VAR = Pattern.compile("(@@(.*?)@@)");
|
||||||
|
|
||||||
public Map<String, Integer> intValues = new HashMap<>();
|
public Map<String, Integer> intValues = new HashMap<>();
|
||||||
|
@ -86,9 +88,11 @@ public class VariableRegistry {
|
||||||
return null;
|
return null;
|
||||||
Matcher m;
|
Matcher m;
|
||||||
while ((m = VAR.matcher(line)).find()) {
|
while ((m = VAR.matcher(line)).find()) {
|
||||||
|
if (m.groupCount() < 2)
|
||||||
|
throw new IllegalStateException("Something broken in: [" + line + "]");
|
||||||
String key = m.group(2);
|
String key = m.group(2);
|
||||||
if (!data.containsKey(key))
|
if (!data.containsKey(key))
|
||||||
throw new IllegalStateException("No such variable: " + key);
|
throw new IllegalStateException("No such variable: [" + key + "]");
|
||||||
String s = data.get(key);
|
String s = data.get(key);
|
||||||
line = m.replaceFirst(s);
|
line = m.replaceFirst(s);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue