X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fcommons%2Fstring%2Ftokenizer%2FTerminator.java;h=8bf6a8dc99db8d1e9f90447cf35162a5590fdf0c;hb=965adace2b47642e2ca84f499cc32683c12059c6;hp=ae51c292a72aaa0ccbffb138d4fefc8d1b064a0b;hpb=84d27634f0fabc23040c258d00b03ff8378c2e77;p=svjatoslav_commons.git diff --git a/src/main/java/eu/svjatoslav/commons/string/tokenizer/Terminator.java b/src/main/java/eu/svjatoslav/commons/string/tokenizer/Terminator.java index ae51c29..8bf6a8d 100755 --- a/src/main/java/eu/svjatoslav/commons/string/tokenizer/Terminator.java +++ b/src/main/java/eu/svjatoslav/commons/string/tokenizer/Terminator.java @@ -1,7 +1,7 @@ /* * Svjatoslav Commons - shared library of common functionality. - * Copyright ©2012-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * + * Copyright ©2012-2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu + * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU Lesser General Public License * or later as published by the Free Software Foundation. @@ -27,6 +27,32 @@ public class Terminator { this.termination = termination; } + public boolean matches(String source, int index) { + // boundary check + if (source.length() < (index + startSequence.length())) + return false; + + // match check + for (int i = 0; i < startSequence.length(); i++) + if (startSequence.charAt(i) != source.charAt(index + i)) + return false; + + return true; + } + + public boolean hasEndSequence() { + return endSequence != null; + } + + @Override + public String toString() { + return "Terminator{" + + "startSequence='" + startSequence + '\'' + + ", endSequence='" + endSequence + '\'' + + ", termination=" + termination + + '}'; + } + public enum TerminationStrategy { PRESERVE, DROP