Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-05 02:50:05 +01:00
Potenially fix quoted string completion
Dieser Commit ist enthalten in:
Ursprung
d134820bcb
Commit
3a5170a0e8
@ -431,7 +431,7 @@ public final class PlatformCommandManager {
|
||||
}
|
||||
|
||||
private Stream<Substring> parseArgs(String input) {
|
||||
return new CommandArgParser(CommandArgParser.spaceSplit(input.substring(1))).parseArgs();
|
||||
return CommandArgParser.forArgString(input.substring(1)).parseArgs();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
@ -31,6 +31,10 @@ import java.util.stream.Stream;
|
||||
|
||||
public class CommandArgParser {
|
||||
|
||||
public static CommandArgParser forArgString(String argString) {
|
||||
return new CommandArgParser(spaceSplit(argString));
|
||||
}
|
||||
|
||||
public static ImmutableList<Substring> spaceSplit(String string) {
|
||||
ImmutableList.Builder<Substring> result = ImmutableList.builder();
|
||||
int index = 0;
|
||||
@ -79,14 +83,14 @@ public class CommandArgParser {
|
||||
if (strPart.endsWith("\"") && strPart.length() > 1) {
|
||||
currentArg.add(Substring.wrap(
|
||||
strPart.substring(1, strPart.length() - 1),
|
||||
part.getStart(), part.getEnd()
|
||||
part.getStart() + 1, part.getEnd() - 1
|
||||
));
|
||||
finishArg();
|
||||
} else {
|
||||
state = State.QUOTE;
|
||||
currentArg.add(Substring.wrap(
|
||||
strPart.substring(1),
|
||||
part.getStart(), part.getEnd()
|
||||
part.getStart() + 1, part.getEnd()
|
||||
));
|
||||
}
|
||||
} else {
|
||||
@ -100,7 +104,7 @@ public class CommandArgParser {
|
||||
state = State.NORMAL;
|
||||
currentArg.add(Substring.wrap(
|
||||
part.getSubstring().substring(0, part.getSubstring().length() - 1),
|
||||
part.getStart(), part.getEnd()
|
||||
part.getStart(), part.getEnd() - 1
|
||||
));
|
||||
finishArg();
|
||||
} else {
|
||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.internal.command;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
|
||||
import com.sk89q.worldedit.internal.util.Substring;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
@ -65,7 +66,9 @@ public class CommandUtil {
|
||||
* Fix {@code suggestions} to replace the last space-separated word in {@code arguments}.
|
||||
*/
|
||||
public static List<String> fixSuggestions(String arguments, List<Substring> suggestions) {
|
||||
Substring lastArg = Iterables.getLast(CommandArgParser.spaceSplit(arguments));
|
||||
Substring lastArg = Iterables.getLast(
|
||||
CommandArgParser.spaceSplit(arguments)
|
||||
);
|
||||
return suggestions.stream()
|
||||
.map(suggestion -> CommandUtil.suggestLast(lastArg, suggestion))
|
||||
.filter(Optional::isPresent)
|
||||
|
@ -23,29 +23,36 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.internal.util.Substring;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static com.sk89q.worldedit.internal.command.CommandArgParser.spaceSplit;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class CommandArgParserTest {
|
||||
class CommandArgParserTest {
|
||||
|
||||
private static List<Substring> argParse(String s) {
|
||||
return CommandArgParser.forArgString(s).parseArgs().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpaceSplit() {
|
||||
void testArgumentParsing() {
|
||||
assertEquals(ImmutableList.of(
|
||||
Substring.wrap("", 0, 0)
|
||||
), spaceSplit(""));
|
||||
), argParse(""));
|
||||
assertEquals(ImmutableList.of(
|
||||
Substring.wrap("ab", 0, 2)
|
||||
), spaceSplit("ab"));
|
||||
), argParse("ab"));
|
||||
assertEquals(ImmutableList.of(
|
||||
Substring.wrap("", 0, 0),
|
||||
Substring.wrap("", 1, 1)
|
||||
), spaceSplit(" "));
|
||||
), argParse(" "));
|
||||
assertEquals(ImmutableList.of(
|
||||
Substring.wrap("a", 0, 1),
|
||||
Substring.wrap("", 2, 2)
|
||||
), spaceSplit("a "));
|
||||
), argParse("a "));
|
||||
assertEquals(ImmutableList.of(
|
||||
Substring.wrap("a", 0, 1),
|
||||
Substring.wrap("b", 2, 3)
|
||||
), spaceSplit("a b"));
|
||||
), argParse("a b"));
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren