2 * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.commons.string.tokenizer;
7 public class Terminator {
9 public final String startSequence;
10 public final String endSequence;
11 public final TerminationStrategy termination;
13 public Terminator(final String startSequence, TerminationStrategy termination) {
14 this.startSequence = startSequence;
15 this.endSequence = null;
16 this.termination = termination;
19 public Terminator(final String startSequence, final String endSequence, TerminationStrategy termination) {
20 this.startSequence = startSequence;
21 this.endSequence = endSequence;
22 this.termination = termination;
25 public boolean matches(String source, int index) {
27 if (source.length() < (index + startSequence.length()))
31 for (int i = 0; i < startSequence.length(); i++)
32 if (startSequence.charAt(i) != source.charAt(index + i))
38 public boolean hasEndSequence() {
39 return endSequence != null;
43 public String toString() {
44 return "Terminator{" +
45 "startSequence='" + startSequence + '\'' +
46 ", endSequence='" + endSequence + '\'' +
47 ", termination=" + termination +
51 public enum TerminationStrategy {