kiwi.text
Class PatternMatcher

java.lang.Object
  |
  +--kiwi.text.PatternMatcher

public class PatternMatcher
extends Object

A simple interface for performing Perl5 regular expression matches on strings and input streams. This class is a beanlike wrapper for the OROMatcher(TM) class library.

Version:
1.0 (05/98)
Author:
Mark Lindner, PING Software Group

Constructor Summary
PatternMatcher()
          Construct a new PatternMatcher.
 
Method Summary
 void disposeSource()
          Release the input source.
 PatternMatch getNextMatch()
          Find the next pattern in the input.
 PatternMatch matches(String text)
          Determine if a string matches the pattern.
 void setIgnoreCase(boolean flag)
          Toggle case sensitivity.
 void setPattern(String pattern)
          Set the regular expression for subsequent pattern matching.
 void setSource(InputStream input)
          Set the source for pattern matching to an input stream.
 void setSource(String input)
          Set the source for pattern matching to a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PatternMatcher

public PatternMatcher()
Construct a new PatternMatcher.
Method Detail

setIgnoreCase

public void setIgnoreCase(boolean flag)
Toggle case sensitivity. If flag is true, case will be ignored in patterns subsequently passed to setPattern(); otherwise, case sensitivity will be on (the default).

setPattern

public void setPattern(String pattern)
                throws IllegalArgumentException
Set the regular expression for subsequent pattern matching.
Parameters:
pattern - The pattern (in Perl5 regular expression syntax).
Throws:
IllegalArgumentException - If the expression is invalid. The exception message will contain the message from the MalformedPatternException.

matches

public PatternMatch matches(String text)
Determine if a string matches the pattern.
Parameters:
text - The string to compare.
Returns:
A PatternMatch object representing to the match, or null if the string did not match the pattern.

setSource

public void setSource(String input)
Set the source for pattern matching to a string. Each subsequent call to findNext() returns the next match found in the string (if any).
Parameters:
input - The input string to search for pattern matches.

setSource

public void setSource(InputStream input)
Set the source for pattern matching to an input stream. Each subsequent call to findNext() returns the next match found in the input stream (if any).

getNextMatch

public PatternMatch getNextMatch()
                          throws IOException
Find the next pattern in the input.
Returns:
A PatternMatch object representing the next match in the input, or null if there are no more matches.

disposeSource

public void disposeSource()
Release the input source. Removes the reference to the current input source (if any).