From 7c46b3418fe1061183aa204a17e38227762c6979 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Wed, 11 Oct 2017 17:44:32 +0300 Subject: [PATCH] Added validation while peeking. --- .../eu/svjatoslav/commons/string/tokenizer/Tokenizer.java | 8 ++++++++ 1 file changed, 8 insertions(+) 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()) -- 2.20.1