Class AutomatonMatcher

java.lang.Object
dk.brics.automaton.AutomatonMatcher
All Implemented Interfaces:
MatchResult

public class AutomatonMatcher extends Object implements MatchResult
A tool that performs match operations on a given character sequence using a compiled automaton.
Author:
John Gibson <jgibson@mitre.org>
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    end()
    Returns the offset after the last character matched.
    int
    end(int group)
    Returns the offset after the last character matched of the specified capturing group.
    boolean
    Find the next matching subsequence of the input.
    Returns the subsequence of the input found by the previous match.
    group(int group)
    Returns the subsequence of the input found by the specified capturing group during the previous match operation.
    int
    Returns the number of capturing groups in the underlying automaton.
    int
    Returns the offset of the first character matched.
    int
    start(int group)
    Returns the offset of the first character matched of the specified capturing group.
    Returns the current state of this AutomatonMatcher as a MatchResult.

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.regex.MatchResult

    end, group, hasMatch, namedGroups, start
  • Method Details

    • find

      public boolean find()
      Find the next matching subsequence of the input.
      This also updates the values for the start, end, and group methods.
      Returns:
      true if there is a matching subsequence.
    • end

      public int end() throws IllegalStateException
      Returns the offset after the last character matched.
      Specified by:
      end in interface MatchResult
      Returns:
      The offset after the last character matched.
      Throws:
      IllegalStateException - if there has not been a match attempt or if the last attempt yielded no results.
    • end

      public int end(int group) throws IndexOutOfBoundsException, IllegalStateException
      Returns 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:
      end in interface MatchResult
      Parameters:
      group - the desired capturing group.
      Returns:
      The offset after the last character matched of the specified capturing group.
      Throws:
      IllegalStateException - if there has not been a match attempt or if the last attempt yielded no results.
      IndexOutOfBoundsException - if the specified capturing group does not exist in the underlying automaton.
    • group

      public String group() throws IllegalStateException
      Returns the subsequence of the input found by the previous match.
      Specified by:
      group in interface MatchResult
      Returns:
      The subsequence of the input found by the previous match.
      Throws:
      IllegalStateException - if there has not been a match attempt or if the last attempt yielded no results.
    • group

      public String group(int group) throws IndexOutOfBoundsException, IllegalStateException
      Returns 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:
      group in interface 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 null if the given group did match.
      Throws:
      IllegalStateException - if there has not been a match attempt or if the last attempt yielded no results.
      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:
      groupCount in interface MatchResult
      Returns:
      The number of capturing groups in the underlying automaton.
    • start

      public int start() throws IllegalStateException
      Returns the offset of the first character matched.
      Specified by:
      start in interface MatchResult
      Returns:
      The offset of the first character matched.
      Throws:
      IllegalStateException - if there has not been a match attempt or if the last attempt yielded no results.
    • start

      public int start(int group) throws IndexOutOfBoundsException, IllegalStateException
      Returns 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:
      start in interface MatchResult
      Parameters:
      group - the desired capturing group.
      Returns:
      The offset of the first character matched of the specified capturing group.
      Throws:
      IllegalStateException - if there has not been a match attempt or if the last attempt yielded no results.
      IndexOutOfBoundsException - if the specified capturing group does not exist in the underlying automaton.
    • toMatchResult

      public MatchResult toMatchResult()
      Returns the current state of this AutomatonMatcher as a MatchResult. The result is unaffected by subsequent operations on this object.
      Returns:
      a MatchResult with the state of this AutomatonMatcher.