net.percederberg.grammatica.parser.re
Class Matcher

java.lang.Object
  |
  +--net.percederberg.grammatica.parser.re.Matcher

public class Matcher
extends java.lang.Object

A regular expression string matcher. This class handles the matching of a specific string with a specific regular expression. It contains state information about the matching process, as for example the position of the latest match, and a number of flags that were set. This class is not thread-safe.


Constructor Summary
protected Matcher(net.percederberg.grammatica.parser.re.Element e, CharBuffer str)
          Creates a new matcher with the specified element.
 
Method Summary
 int end()
          Returns the end position of the latest match.
 boolean hasReadEndOfString()
          Checks if the end of the string was encountered during the last match attempt.
 int length()
          Returns the length of the latest match.
 boolean matchFrom(int pos)
          Attempts to find a match starting at the specified position in the string.
 boolean matchFromBeginning()
          Attempts to find a match starting at the beginning of the string.
 void reset()
          Resets the information about the last match.
 int start()
          Returns the start position of the latest match.
 java.lang.String toString()
          Returns the latest matched string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Matcher

protected Matcher(net.percederberg.grammatica.parser.re.Element e,
                  CharBuffer str)
Creates a new matcher with the specified element.

Parameters:
e - the base regular expression element
str - the string to work with
Method Detail

reset

public void reset()
Resets the information about the last match. This will clear all flags and set the match length to a negative value. This method is automatically called by all matching methods.


start

public int start()
Returns the start position of the latest match. If no match has been encountered, this method returns zero (0).

Returns:
the start position of the latest match

end

public int end()
Returns the end position of the latest match. This is one character after the match end, i.e. the first character after the match. If no match has been encountered, this method returns the same value as start().

Returns:
the end position of the latest match

length

public int length()
Returns the length of the latest match.

Returns:
the length of the latest match, or -1 if no match was found

hasReadEndOfString

public boolean hasReadEndOfString()
Checks if the end of the string was encountered during the last match attempt. This flag signals that more input may be needed in order to get a match (or a longer match).

Returns:
true if the end of string was encountered, or false otherwise

matchFromBeginning

public boolean matchFromBeginning()
Attempts to find a match starting at the beginning of the string.

Returns:
true if a match was found, or false otherwise

matchFrom

public boolean matchFrom(int pos)
Attempts to find a match starting at the specified position in the string.

Parameters:
pos - the starting position of the match
Returns:
true if a match was found, or false otherwise

toString

public java.lang.String toString()
Returns the latest matched string. If no string has been matched, an empty string will be returned.

Overrides:
toString in class java.lang.Object
Returns:
the latest matched string