Fixes various tab completion problems

This commit is contained in:
2022-02-27 14:28:46 +01:00
parent 91d477b45a
commit 3b7268d2ff
8 changed files with 52 additions and 38 deletions

View File

@ -15,10 +15,21 @@ public final class Tokenizer {
/**
* Tokenizes a string
*
* @param input <p>A string.</p>
* @return <p>A list of tokens.</p>
* @param input <p>A string</p>
* @return <p>A list of tokens</p>
*/
public static List<String> tokenize(String input) {
return tokenize(input, true);
}
/**
* Tokenizes a string
*
* @param input <p>A string</p>
* @param allowEmptyQuotes <p>Whether to treat "" as a token</p>
* @return <p>A list of tokens</p>
*/
public static List<String> tokenize(String input, boolean allowEmptyQuotes) {
List<String> tokens = new ArrayList<>();
boolean startedQuote = false;
StringBuilder currentToken = new StringBuilder();
@ -33,7 +44,7 @@ public final class Tokenizer {
case '"':
if (startedQuote) {
//This quote signifies the end of the argument
if (isNotEmpty(currentToken)) {
if (allowEmptyQuotes || isNotEmpty(currentToken)) {
tokens.add(currentToken.toString());
currentToken = new StringBuilder();
}