Skip to content

Commit

Permalink
Greedy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Mqzn committed Oct 8, 2024
1 parent bf92862 commit ff8f497
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,23 @@ public final class ParameterString<S extends Source> extends BaseParameterType<S
@Override
public @Nullable String resolve(ExecutionContext<S> context, @NotNull CommandInputStream<S> inputStream) throws ImperatException {
StringBuilder builder = new StringBuilder();
final CommandParameter<S> parameter = inputStream.currentParameter();
assert parameter != null;

final Character current = inputStream.currentLetter();
if (current == null) return null;

if (!isQuoteChar(current)) {
return inputStream.currentRaw();
builder.append(inputStream.currentRaw());

if (parameter.isGreedy()) {
while (inputStream.hasNextRaw()) {
inputStream.popRaw()
.ifPresent(builder::append);
}
}

return builder.toString();
}

Character next;
Expand All @@ -38,6 +50,13 @@ public final class ParameterString<S extends Source> extends BaseParameterType<S
} while (inputStream.hasNextLetter() &&
inputStream.peekLetter().filter((ch) -> !isQuoteChar(ch)).isPresent());

if (parameter.isGreedy()) {
while (inputStream.hasNextRaw()) {
inputStream.popRaw()
.ifPresent(builder::append);
}
}

return builder.toString();
}

Expand Down

0 comments on commit ff8f497

Please sign in to comment.