Code cleanup and formatting.
[svjatoslav_commons.git] / src / main / java / eu / svjatoslav / commons / string / tokenizer / Terminator.java
index ae51c29..8dc20ac 100755 (executable)
@@ -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