Skip to content

Commit

Permalink
change behavior of #peekString() to allow unclosed quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
Revxrsal committed Dec 10, 2024
1 parent 5552631 commit ecd5783
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ public char read() {
}

public @NotNull String readUntil(char delimiter) {
return readUntil(delimiter, false);
}

public @NotNull String readUntil(char delimiter, boolean allowUnclosed) {
StringBuilder result = new StringBuilder();
boolean escaped = false;
while (hasRemaining()) {
Expand All @@ -163,14 +167,24 @@ public char read() {
result.append(c);
}
}
throw new InputParseException(InputParseException.Cause.UNCLOSED_QUOTE);
if (allowUnclosed)
return result.toString();
else
throw new InputParseException(InputParseException.Cause.UNCLOSED_QUOTE);
}

@Override public @NotNull String peekString() {
if (!hasRemaining())
return "";
int cursor = pos;
String value = readString();
pos = cursor;
return value;
char next = peek();
if (next == DOUBLE_QUOTE) {
pos += 1;
String result = readUntil(DOUBLE_QUOTE, true);
pos = cursor;
return result;
}
return peekUnquotedString();
}

public @NotNull String peekUnquotedString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ public interface StringStream {
* peek the next string until a whitespace character is encountered.
* <p>
* This will not move the cursor forward.
* <p>
* Note that, if the next string is an unclosed-quoted string, it will return
* the content inside the unclosed quote.
*
* @return The next string.
*/
Expand Down

0 comments on commit ecd5783

Please sign in to comment.