Package dk.brics.automaton
Class AutomatonMatcher
- java.lang.Object
-
- dk.brics.automaton.AutomatonMatcher
-
- All Implemented Interfaces:
java.util.regex.MatchResult
public class AutomatonMatcher extends java.lang.Object implements java.util.regex.MatchResultA tool that performs match operations on a given character sequence using a compiled automaton.
-
-
Field Summary
Fields Modifier and Type Field Description private RunAutomatonautomatonprivate java.lang.CharSequencecharsprivate intmatchEndprivate intmatchStart
-
Constructor Summary
Constructors Constructor Description AutomatonMatcher(java.lang.CharSequence chars, RunAutomaton automaton)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intend()Returns the offset after the last character matched.intend(int group)Returns the offset after the last character matched of the specified capturing group.booleanfind()Find the next matching subsequence of the input.private java.lang.CharSequencegetChars()private intgetMatchEnd()private intgetMatchStart()java.lang.Stringgroup()Returns the subsequence of the input found by the previous match.java.lang.Stringgroup(int group)Returns the subsequence of the input found by the specified capturing group during the previous match operation.intgroupCount()Returns the number of capturing groups in the underlying automaton.private voidmatchGood()Helper method to check that the last match attempt was valid.private static voidonlyZero(int group)Helper method that requires the group argument to be 0.private voidsetMatch(int matchStart, int matchEnd)intstart()Returns the offset of the first character matched.intstart(int group)Returns the offset of the first character matched of the specified capturing group.java.util.regex.MatchResulttoMatchResult()Returns the current state of thisAutomatonMatcheras aMatchResult.
-
-
-
Field Detail
-
automaton
private final RunAutomaton automaton
-
chars
private final java.lang.CharSequence chars
-
matchStart
private int matchStart
-
matchEnd
private int matchEnd
-
-
Constructor Detail
-
AutomatonMatcher
AutomatonMatcher(java.lang.CharSequence chars, RunAutomaton automaton)
-
-
Method Detail
-
find
public boolean find()
Find the next matching subsequence of the input.
This also updates the values for thestart,end, andgroupmethods.- Returns:
trueif there is a matching subsequence.
-
setMatch
private void setMatch(int matchStart, int matchEnd) throws java.lang.IllegalArgumentException- Throws:
java.lang.IllegalArgumentException
-
getMatchStart
private int getMatchStart()
-
getMatchEnd
private int getMatchEnd()
-
getChars
private java.lang.CharSequence getChars()
-
end
public int end() throws java.lang.IllegalStateExceptionReturns the offset after the last character matched.- Specified by:
endin interfacejava.util.regex.MatchResult- Returns:
- The offset after the last character matched.
- Throws:
java.lang.IllegalStateException- if there has not been a match attempt or if the last attempt yielded no results.
-
end
public int end(int group) throws java.lang.IndexOutOfBoundsException, java.lang.IllegalStateExceptionReturns the offset after the last character matched of the specified capturing group.
Note that because the automaton does not support capturing groups the only valid group is 0 (the entire match).- Specified by:
endin interfacejava.util.regex.MatchResult- Parameters:
group- the desired capturing group.- Returns:
- The offset after the last character matched of the specified capturing group.
- Throws:
java.lang.IllegalStateException- if there has not been a match attempt or if the last attempt yielded no results.java.lang.IndexOutOfBoundsException- if the specified capturing group does not exist in the underlying automaton.
-
group
public java.lang.String group() throws java.lang.IllegalStateExceptionReturns the subsequence of the input found by the previous match.- Specified by:
groupin interfacejava.util.regex.MatchResult- Returns:
- The subsequence of the input found by the previous match.
- Throws:
java.lang.IllegalStateException- if there has not been a match attempt or if the last attempt yielded no results.
-
group
public java.lang.String group(int group) throws java.lang.IndexOutOfBoundsException, java.lang.IllegalStateExceptionReturns the subsequence of the input found by the specified capturing group during the previous match operation.
Note that because the automaton does not support capturing groups the only valid group is 0 (the entire match).- Specified by:
groupin interfacejava.util.regex.MatchResult- Parameters:
group- the desired capturing group.- Returns:
- The subsequence of the input found by the specified capturing
group during the previous match operation the previous match. Or
nullif the given group did match. - Throws:
java.lang.IllegalStateException- if there has not been a match attempt or if the last attempt yielded no results.java.lang.IndexOutOfBoundsException- if the specified capturing group does not exist in the underlying automaton.
-
groupCount
public int groupCount()
Returns the number of capturing groups in the underlying automaton.
Note that because the automaton does not support capturing groups this method will always return 0.- Specified by:
groupCountin interfacejava.util.regex.MatchResult- Returns:
- The number of capturing groups in the underlying automaton.
-
start
public int start() throws java.lang.IllegalStateExceptionReturns the offset of the first character matched.- Specified by:
startin interfacejava.util.regex.MatchResult- Returns:
- The offset of the first character matched.
- Throws:
java.lang.IllegalStateException- if there has not been a match attempt or if the last attempt yielded no results.
-
start
public int start(int group) throws java.lang.IndexOutOfBoundsException, java.lang.IllegalStateExceptionReturns the offset of the first character matched of the specified capturing group.
Note that because the automaton does not support capturing groups the only valid group is 0 (the entire match).- Specified by:
startin interfacejava.util.regex.MatchResult- Parameters:
group- the desired capturing group.- Returns:
- The offset of the first character matched of the specified capturing group.
- Throws:
java.lang.IllegalStateException- if there has not been a match attempt or if the last attempt yielded no results.java.lang.IndexOutOfBoundsException- if the specified capturing group does not exist in the underlying automaton.
-
toMatchResult
public java.util.regex.MatchResult toMatchResult()
Returns the current state of thisAutomatonMatcheras aMatchResult. The result is unaffected by subsequent operations on this object.- Returns:
- a
MatchResultwith the state of thisAutomatonMatcher.
-
onlyZero
private static void onlyZero(int group) throws java.lang.IndexOutOfBoundsExceptionHelper method that requires the group argument to be 0.- Throws:
java.lang.IndexOutOfBoundsException
-
matchGood
private void matchGood() throws java.lang.IllegalStateExceptionHelper method to check that the last match attempt was valid.- Throws:
java.lang.IllegalStateException
-
-