Prepare the Matcher class for multiple groups

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin 2013-11-22 14:41:29 -06:00
parent e6ad10de04
commit 2073d4bffb
2 changed files with 50 additions and 0 deletions

View File

@ -87,4 +87,33 @@ public abstract class Matcher {
public int end() {
return end;
}
public String group() {
return input.subSequence(start, end).toString();
}
public int start(int group) {
if (group == 0) {
return start();
}
throw new UnsupportedOperationException();
}
public int end(int group) {
if (group == 0) {
return end();
}
throw new UnsupportedOperationException();
}
public String group(int group) {
if (group == 0) {
return group();
}
throw new UnsupportedOperationException();
}
public int groupCount() {
return 0;
}
}

View File

@ -52,4 +52,25 @@ public class RegexMatcher extends Matcher {
public boolean find(int offset) {
throw new UnsupportedOperationException("TODO");
}
public int start(int group) {
return groupStart[group];
}
public int end(int group) {
return groupEnd[group];
}
public String group(int group) {
int offset = start(group);
if (offset < 0) {
return null;
}
int length = end(group) - offset;
return new String(array, offset, length);
}
public int groupCount() {
return groupStart.length - 1;
}
}