From: Svjatoslav Agejenko Date: Wed, 11 Oct 2017 14:44:32 +0000 (+0300) Subject: Added validation while peeking. X-Git-Tag: svjatoslavcommons-1.8~55 X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=7c46b3418fe1061183aa204a17e38227762c6979;p=svjatoslav_commons.git Added validation while peeking. --- diff --git a/src/main/java/eu/svjatoslav/commons/string/tokenizer/Tokenizer.java b/src/main/java/eu/svjatoslav/commons/string/tokenizer/Tokenizer.java index ba1590d..cd5e5c0 100755 --- a/src/main/java/eu/svjatoslav/commons/string/tokenizer/Tokenizer.java +++ b/src/main/java/eu/svjatoslav/commons/string/tokenizer/Tokenizer.java @@ -120,6 +120,14 @@ public class Tokenizer { return false; } + public void peekExpectNoneOf(String [] ... possibilities) throws InvalidSyntaxException { + TokenizerMatch nextToken = peekNextToken(); + + for (String[] possibility : possibilities) + if (possibility.equals(nextToken)) + throw new InvalidSyntaxException("Not expected \"" + nextToken + "\" here."); + } + public boolean sequenceMatches(final String sequence) { if ((currentIndex + sequence.length()) > source.length())