Skip to content

Commit

Permalink
added API methods
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille committed Oct 5, 2023
1 parent 4ea2a2f commit 988cbb4
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions core/src/main/java/io/github/mmm/scanner/CharStreamScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ public interface CharStreamScanner extends TextFormatProcessor {
*/
String peekWhile(CharFilter filter, int maxLen);

/**
* @param stopFilter the {@link CharFilter} that decides which characters to {@link CharFilter#accept(char) accept} as
* stop characters.
* @param maxLen the maximum number of characters to peek (get as lookahead without modifying this stream).
* @return a {@link String} with the {@link #peek() peeked} characters of the given {@code maxLen} or less if a stop
* character was hit or the end-of-text has been reached before. The state of this stream remains unchanged.
* @see #readWhile(CharFilter)
* @see #skip(int)
*/
default String peekUntil(CharFilter stopFilter, int maxLen) {

return peekWhile(stopFilter.negate(), maxLen);
}

/**
* This method reads the number of {@link #next() next characters} given by {@code count} and returns them as string.
* If there are less characters {@link #hasNext() available} the returned string will be shorter than {@code count}
Expand Down Expand Up @@ -288,6 +302,22 @@ default String readUntil(CharFilter filter, boolean acceptEnd, String stop, bool
*/
String readUntil(CharFilter filter, boolean acceptEnd, CharScannerSyntax syntax);

/**
* @param stopFilter the {@link CharFilter} that decides which characters to {@link CharFilter#accept(char) accept} as
* stop characters.
* @param maxLength the (maximum) length of the characters to consume.
* @return the {@link String} with all consumed characters excluding the stop character. If no {@code stop} character
* was found until {@code maxLength} characters have been consumed, this method behaves like {@link #read(int)
* read(maxLength)}.
* @see #read(int)
* @see #readWhile(CharFilter, int)
* @see #peekUntil(CharFilter, int)
*/
default String readUntil(CharFilter stopFilter, int maxLength) {

return readWhile(stopFilter.negate(), maxLength);
}

/**
* This method reads all {@link #next() next characters} that are {@link CharFilter#accept(char) accepted} by the
* given {@code filter}. <br>
Expand Down

0 comments on commit 988cbb4

Please sign in to comment.