allowing tabs while making code less confusing
This commit is contained in:
parent
c071074475
commit
9f6bce544d
|
@ -3,8 +3,10 @@ package com.rusefi;
|
|||
import com.devexperts.logging.Logging;
|
||||
import com.opensr5.ini.RawIniFile;
|
||||
import com.opensr5.ini.field.EnumIniField;
|
||||
import com.rusefi.core.Pair;
|
||||
import com.rusefi.enum_reader.Value;
|
||||
import com.rusefi.output.*;
|
||||
import com.rusefi.parse.TokenUtil;
|
||||
import com.rusefi.parse.TypesHelper;
|
||||
import com.rusefi.util.LazyFile;
|
||||
import com.rusefi.util.SystemOut;
|
||||
|
@ -146,20 +148,20 @@ public class ReaderStateImpl implements ReaderState {
|
|||
}
|
||||
|
||||
private void handleCustomLine(String customLineWithPrefix) {
|
||||
String line = customLineWithPrefix.substring(CUSTOM.length() + 1).trim();
|
||||
int index = line.indexOf(' ');
|
||||
String name = line.substring(0, index);
|
||||
String withoutPrefix = customLineWithPrefix.substring(CUSTOM.length() + 1).trim();
|
||||
Pair<String, String> nameAndRest = TokenUtil.grabFirstTokenAndTheRest(withoutPrefix);
|
||||
String name = nameAndRest.first;
|
||||
|
||||
String autoEnumOptions = variableRegistry.getEnumOptionsForTunerStudio(enumsReader, name);
|
||||
if (autoEnumOptions != null) {
|
||||
variableRegistry.register(name + VariableRegistry.AUTO_ENUM_SUFFIX, autoEnumOptions);
|
||||
}
|
||||
|
||||
line = line.substring(index).trim();
|
||||
index = line.indexOf(' ');
|
||||
String customSize = line.substring(0, index);
|
||||
String line = nameAndRest.second;
|
||||
Pair<String, String> sizeAndRest = TokenUtil.grabFirstTokenAndTheRest(line);
|
||||
String customSize = sizeAndRest.first;
|
||||
|
||||
String tunerStudioLine = line.substring(index).trim();
|
||||
String tunerStudioLine = sizeAndRest.second;
|
||||
tunerStudioLine = variableRegistry.applyVariables(tunerStudioLine);
|
||||
int size = parseSize(customSize, line);
|
||||
tsCustomSize.put(name, size);
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package com.rusefi.parse;
|
||||
|
||||
import com.rusefi.core.Pair;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class TokenUtil {
|
||||
private static final Pattern pattern = Pattern.compile("\\s");
|
||||
|
||||
public static Pair<String, String> grabFirstTokenAndTheRest(String line) {
|
||||
Matcher matcher = pattern.matcher(line);
|
||||
if (!matcher.find())
|
||||
throw new IllegalStateException("whitespace expected in [" + line + "]");
|
||||
int index = matcher.start();
|
||||
String first = line.substring(0, index);
|
||||
|
||||
String second = line.substring(index).trim();
|
||||
return new Pair<>(first, second);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.rusefi.parse;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class TokenUtilTest {
|
||||
@Test
|
||||
public void test() {
|
||||
assertEquals("first", TokenUtil.grabFirstTokenAndTheRest("first s").first);
|
||||
assertEquals("second", TokenUtil.grabFirstTokenAndTheRest("f second \t").second);
|
||||
assertEquals("second", TokenUtil.grabFirstTokenAndTheRest("f\tsecond\t ").second);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue