Added validation while peeking.
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Wed, 11 Oct 2017 14:44:32 +0000 (17:44 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Wed, 11 Oct 2017 14:44:32 +0000 (17:44 +0300)
src/main/java/eu/svjatoslav/commons/string/tokenizer/Tokenizer.java

index ba1590d..cd5e5c0 100755 (executable)
@@ -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())