From 2073d4bffb992151eb97545b9284390a3a7b5adc Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 22 Nov 2013 14:41:29 -0600 Subject: [PATCH] Prepare the Matcher class for multiple groups Signed-off-by: Johannes Schindelin --- test/regex/Matcher.java | 29 +++++++++++++++++++++++++++++ test/regex/RegexMatcher.java | 21 +++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/test/regex/Matcher.java b/test/regex/Matcher.java index fc99d201e3..13c2efba1a 100644 --- a/test/regex/Matcher.java +++ b/test/regex/Matcher.java @@ -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; + } } diff --git a/test/regex/RegexMatcher.java b/test/regex/RegexMatcher.java index 7a266d805d..5ea2eea82c 100644 --- a/test/regex/RegexMatcher.java +++ b/test/regex/RegexMatcher.java @@ -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; + } }