X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fcommons%2Fstring%2Ftokenizer%2FTerminator.java;h=1a6c5eeb5650d0ff87a4427a14337729e13c29e8;hb=37f0e9901f9ecaea7a28cba616e247415ebb9ea0;hp=fa07a5b1d4d181f207ce7455b99d7e894c94a730;hpb=d179c8161ada24635c95d30ad6033cfc6d6e3d8a;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 fa07a5b..1a6c5ee 100755 --- a/src/main/java/eu/svjatoslav/commons/string/tokenizer/Terminator.java +++ b/src/main/java/eu/svjatoslav/commons/string/tokenizer/Terminator.java @@ -1,12 +1,7 @@ /* - * Svjatoslav Commons - shared library of common functionality. - * Copyright ©2012-2017, 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. + * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko. + * This project is released under Creative Commons Zero (CC0) license. */ - package eu.svjatoslav.commons.string.tokenizer; public class Terminator { @@ -27,9 +22,21 @@ public class Terminator { this.termination = termination; } - public enum TerminationStrategy { - PRESERVE, - DROP + 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 @@ -40,4 +47,9 @@ public class Terminator { ", termination=" + termination + '}'; } + + public enum TerminationStrategy { + PRESERVE, // Identify and return such tokens for further processing. + DROP // Identify but ignore such tokens, do not return them. Good for handling comments in scripts. + } }