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 import java.util.regex.Matcher;
9 public class TokenizerMatch {
11 public final String token;
14 * {@link Terminator} that matched current token
16 public final Terminator terminator;
18 public final Matcher matcher;
20 private Tokenizer tokenizer;
22 public TokenizerMatch(final String token, final Terminator terminator, Matcher matcher, Tokenizer tokenizer) {
24 this.terminator = terminator;
25 this.matcher = matcher;
26 this.tokenizer = tokenizer;
29 public boolean isGroup(String group){
30 if (terminator == null){
34 if (terminator.group == null){
38 return terminator.group.equals(group);
41 public String[] getRegExpGroups(){
42 if (matcher == null) return new String[]{};
44 String[] result = new String[matcher.groupCount()];
46 for (int i = 0; i< result.length; i++){
47 result[i] = matcher.group(i+1);
54 public String toString() {
55 StringBuilder result = new StringBuilder();
56 result.append("TokenizerMatch\n" +
57 " token='" + token + "'\n" +
58 " terminator=" + terminator + "\n" +
62 for (String s : getRegExpGroups()) {
63 result.append(" " + i + ": " + s + "\n");
67 return result.toString();
70 public Tokenizer getTokenizer() {