addSuffix(value);
}
+ public String2() {
+ }
+
public String2 repeat(int count){
String value = toString();
return this;
}
+ public String2 addSuffix(String s, int times) {
+ for (int i = 0; i < times; i++) addSuffix(s);
+ return this;
+ }
+
+
/**
* Cut given amount of characters from the left of the string.
*
if (currentIndex >= source.length()) { // reached end of input
if (hasAccumulatedToken(tokenAccumulator))
- return new TokenizerMatch(tokenAccumulator.toString(), null, null);
+ return new TokenizerMatch(tokenAccumulator.toString(), null, null, this);
else
return null;
}
if (matchResult.terminator.termination == PRESERVE) {
if (hasAccumulatedToken(tokenAccumulator))
- return new TokenizerMatch(tokenAccumulator.toString(), null, null);
+ return new TokenizerMatch(tokenAccumulator.toString(), null, null, this);
currentIndex = matchResult.matcher.end();
return matchResult;
currentIndex = matchResult.matcher.end();
if (hasAccumulatedToken(tokenAccumulator))
- return new TokenizerMatch(tokenAccumulator.toString(), null, null);
+ return new TokenizerMatch(tokenAccumulator.toString(), null, null, this);
}
}
}
Matcher match = terminator.match(source, currentIndex);
if (match.find()) {
String token = source.substring(match.start(), match.end());
- return new TokenizerMatch(token, terminator, match);
+ return new TokenizerMatch(token, terminator, match, this);
}
}
return null;
public final Matcher matcher;
+ private Tokenizer tokenizer;
- public TokenizerMatch(final String token, final Terminator terminator, Matcher matcher) {
+ public TokenizerMatch(final String token, final Terminator terminator, Matcher matcher, Tokenizer tokenizer) {
this.token = token;
this.terminator = terminator;
this.matcher = matcher;
+ this.tokenizer = tokenizer;
}
public boolean isGroup(String group){
return terminator.group.equals(group);
}
+ public String[] getRegExpGroups(){
+ String[] result = new String[matcher.groupCount()];
+
+ for (int i = 0; i< result.length; i++){
+ result[i] = matcher.group(i+1);
+ }
+
+ return result;
+ }
+
@Override
public String toString() {
return "TokenizerMatch{" +
", terminator=" + terminator +
'}';
}
+
+ public Tokenizer getTokenizer() {
+ return tokenizer;
+ }
}