diff options
Diffstat (limited to 'java/util/regex/Matcher.java')
-rw-r--r-- | java/util/regex/Matcher.java | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/java/util/regex/Matcher.java b/java/util/regex/Matcher.java index cc2a2e5e9..a6f34a63b 100644 --- a/java/util/regex/Matcher.java +++ b/java/util/regex/Matcher.java @@ -171,7 +171,7 @@ public final class Matcher implements MatchResult int endIndex = match.getEndIndex(); // Are we stuck at the same position? if (!first && endIndex == position) - { + { match = null; // Not at the end of the input yet? if (position < input.length() - 1) @@ -590,4 +590,20 @@ public final class Matcher implements MatchResult return this; } + /** + * Returns a read-only snapshot of the current state of + * the {@link Matcher} as a {@link MatchResult}. Any + * subsequent changes to this instance are not reflected + * in the returned {@link MatchResult}. + * + * @return a {@link MatchResult} instance representing the + * current state of the {@link Matcher}. + */ + public MatchResult toMatchResult() + { + Matcher snapshot = new Matcher(pattern, input); + snapshot.match = (REMatch) match.clone(); + return snapshot; + } + } |