Fix string tokenizer (#2538)
* Fix * Parse quote and double quote at the same time. Add TokenizerTest. * Simplify TokenizerTest * Fix handling multiple space * Fix handling empty part * Supports escape sequences * Remove an unnecessary lambda. --------- Co-authored-by: Burning_TNT <pangyl08@163.com“> Co-authored-by: Glavo <zjx001202@gmail.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package org.jackhuang.hmcl.util;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class TokenizerTest {
|
||||
private void test(String source, String... expected) {
|
||||
Assertions.assertEquals(Arrays.asList(expected), StringUtils.tokenize(source));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void textTokenizer() {
|
||||
test(
|
||||
"\"C:/Program Files/Bellsoft/JDK-11/bin.java.exe\" -version \"a.b.c\" something else",
|
||||
"C:/Program Files/Bellsoft/JDK-11/bin.java.exe", "-version", "a.b.c", "something", "else"
|
||||
);
|
||||
test(
|
||||
"\"Another\"Text something else",
|
||||
"AnotherText", "something", "else"
|
||||
);
|
||||
test(
|
||||
"Text without quote",
|
||||
"Text", "without", "quote"
|
||||
);
|
||||
test(
|
||||
"Text with multiple spaces",
|
||||
"Text", "with", "multiple", "spaces"
|
||||
);
|
||||
test(
|
||||
"Text with empty part ''",
|
||||
"Text", "with", "empty", "part", ""
|
||||
);
|
||||
test(
|
||||
"head\"abc\\n\\\\\\\"\"end",
|
||||
"headabc\n\\\"end"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user