Class com.oroinc.text.regex.PatternMatcherInput
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.oroinc.text.regex.PatternMatcherInput

java.lang.Object
   |
   +----com.oroinc.text.regex.PatternMatcherInput

public final class PatternMatcherInput
extends Object
The PatternMatcherInput class is used to preserve state across calls to the contains() methods of PatternMatcher instances. It is also used to specify that only a subregion of a string should be used as input when looking for a pattern match. All that is meant by preserving state is that the end offset of the last match is remembered, so that the next match is performed from that point where the last match left off. This offset can be accessed from the getCurrentOffset() method and can be set with the setCurrentOffset(int) method.

You would use a PatternMatcherInput object when you want to search for more than just the first occurrence of a pattern in a string, or when you only want to search a subregion of the string for a match. An example of its most common use is:

PatternMatcher matcher;
PatternCompiler compiler;
Pattern pattern;
PatternMatcherInput input;
MatchResult result;
compiler = new Perl5Compiler();
matcher  = new Perl5Matcher();
try {
  pattern = compiler.compile(somePatternString);
} catch(MalformedPatternException e) {
  System.out.println("Bad pattern.");
  System.out.println(e.getMessage());
  return;
}
input   = new PatternMatcherInput(someStringInput);
while(matcher.contains(input, pattern)) {
  result = matcher.getMatch();  
  // Perform whatever processing on the result you want.
  // Here we just print out all its elements to show how its
  // methods are used.
}
// Suppose we want to start searching from the beginning again with
// a different pattern.
// Just set the current offset to the begin offset.
input.setCurrentOffset(input.getBeginOffset());
// Second search omitted
// Suppose we're done with this input, but want to search another string.
// There's no need to create another PatternMatcherInput instance.
// We can just use the setInput() method.
input.setInput(aNewInputString);

Copyright © 1997 Original Resuable Objects, Inc. All rights reserved.

Author:
Daniel F. Savarese
See Also:
PatternMatcher

Constructor Index

 o PatternMatcherInput(char[])
Like calling:
PatternMatcherInput(input, 0, input.length);

 o PatternMatcherInput(char[], int, int)
Creates a PatternMatcherInput object, associating a region of a string (represented as a char[]) as input to be used for pattern matching by PatternMatcher objects.
 o PatternMatcherInput(String)
Like calling
PatternMatcherInput(input, 0, input.length());

 o PatternMatcherInput(String, int, int)
Creates a PatternMatcherInput object, associating a region of a String as input to be used for pattern matching by PatternMatcher objects.

Method Index

 o endOfInput()
Returns whether or not the end of the input has been reached.
 o getBeginOffset()
 o getCurrentOffset()
 o getEndOffset()
 o getInput()
Retrieves the original input used to initialize the PatternMatcherInput instance.
 o length()
 o setBeginOffset(int)
Sets the offset of the input that should be considered the start of the region to be considered as input by PatternMatcher methods.
 o setCurrentOffset(int)
Sets the offset of the input that should be considered the current offset where PatternMatcher methods should start looking for matches.
 o setEndOffset(int)
Sets the offset of the input that should be considered the end of the region to be considered as input by PatternMatcher methods.
 o setInput(char[])
This method is identical to calling:
setInput(input, 0, input.length);

 o setInput(char[], int, int)
Associates a region of a string (represented as a char[]) as input to be used for pattern matching by PatternMatcher objects.
 o setInput(String)
This method is identical to calling:
setInput(input, 0, input.length());

 o setInput(String, int, int)
Associates a region of a String as input to be used for pattern matching by PatternMatcher objects.

Constructors

 o PatternMatcherInput
  public PatternMatcherInput(String input,
                             int begin,
                             int length)
Creates a PatternMatcherInput object, associating a region of a String as input to be used for pattern matching by PatternMatcher objects. A copy of the string is not made, therefore you should not modify the string unless you know what you are doing. The current offset of the PatternMatcherInput is set to the begin offset of the region.

Parameters:
input - The input to associate with the PatternMatcherInput.
begin - The offset into the char[] to use as the beginning of the input.
length - The length of the reegion starting from the begin offset to use as the input for pattern matching purposes.
 o PatternMatcherInput
  public PatternMatcherInput(String input)
Like calling
PatternMatcherInput(input, 0, input.length());

Parameters:
input - The input to associate with the PatternMatcherInput.
 o PatternMatcherInput
  public PatternMatcherInput(char input[],
                             int begin,
                             int length)
Creates a PatternMatcherInput object, associating a region of a string (represented as a char[]) as input to be used for pattern matching by PatternMatcher objects. A copy of the string is not made, therefore you should not modify the string unless you know what you are doing. The current offset of the PatternMatcherInput is set to the begin offset of the region.

Parameters:
input - The input to associate with the PatternMatcherInput.
begin - The offset into the char[] to use as the beginning of the input.
length - The length of the reegion starting from the begin offset to use as the input for pattern matching purposes.
 o PatternMatcherInput
  public PatternMatcherInput(char input[])
Like calling:
PatternMatcherInput(input, 0, input.length);

Parameters:
input - The input to associate with the PatternMatcherInput.

Methods

 o length
  public int length()
Returns:
The length of the region to be considered input for pattern matching purposes. Essentially this is then end offset minus the begin offset.
 o setInput
  public void setInput(String input,
                       int begin,
                       int length)
Associates a region of a String as input to be used for pattern matching by PatternMatcher objects. The current offset of the PatternMatcherInput is set to the begin offset of the region.

Parameters:
input - The input to associate with the PatternMatcherInput.
begin - The offset into the String to use as the beginning of the input.
length - The length of the reegion starting from the begin offset to use as the input for pattern matching purposes.
 o setInput
  public void setInput(String input)
This method is identical to calling:
setInput(input, 0, input.length());

Parameters:
input - The input to associate with the PatternMatcherInput.
 o setInput
  public void setInput(char input[],
                       int begin,
                       int length)
Associates a region of a string (represented as a char[]) as input to be used for pattern matching by PatternMatcher objects. A copy of the string is not made, therefore you should not modify the string unless you know what you are doing. The current offset of the PatternMatcherInput is set to the begin offset of the region.

Parameters:
input - The input to associate with the PatternMatcherInput.
begin - The offset into the char[] to use as the beginning of the input.
length - The length of the reegion starting from the begin offset to use as the input for pattern matching purposes.
 o setInput
  public void setInput(char input[])
This method is identical to calling:
setInput(input, 0, input.length);

Parameters:
input - The input to associate with the PatternMatcherInput.
 o getInput
  public Object getInput()
Retrieves the original input used to initialize the PatternMatcherInput instance. If a String was used, the String instance will be returned. If a char[] was used, a char instance will be returned.

Returns:
The String or char[] input used to initialize the PatternMatcherInput instance.
 o endOfInput
  public boolean endOfInput()
Returns whether or not the end of the input has been reached.

Returns:
True if the current offset is greater than or equal to the end offset.
 o getBeginOffset
  public int getBeginOffset()
Returns:
The offset of the input that should be considered the start of the region to be considered as input by PatternMatcher methods.
 o getEndOffset
  public int getEndOffset()
Returns:
The offset of the input that should be considered the end of the region to be considered as input by PatternMatcher methods. This offset is actually 1 plus the last offset that is part of the input region.
 o getCurrentOffset
  public int getCurrentOffset()
Returns:
The offset of the input that should be considered the current offset where PatternMatcher methods should start looking for matches.
 o setBeginOffset
  public void setBeginOffset(int offset)
Sets the offset of the input that should be considered the start of the region to be considered as input by PatternMatcher methods. In other words, everything before this offset is ignored by a PatternMatcher.

Parameters:
offset - The offset to use as the beginning of the input.
 o setEndOffset
  public void setEndOffset(int offset)
Sets the offset of the input that should be considered the end of the region to be considered as input by PatternMatcher methods. This offset is actually 1 plus the last offset that is part of the input region.

Parameters:
offset - The offset to use as the end of the input.
 o setCurrentOffset
  public void setCurrentOffset(int offset)
Sets the offset of the input that should be considered the current offset where PatternMatcher methods should start looking for matches.

Parameters:
offset - The offset to use as the current offset.

All Packages  Class Hierarchy  This Package  Previous  Next  Index