org.apache.oro.text.awk
public final class AwkMatcher extends Object implements PatternMatcher
It is important for you to remember that AwkMatcher does not save parenthesized sub-group information. Therefore the number of groups saved in a MatchResult produced by AwkMatcher will always be 1.
Since: 1.0
Version: 2.0.8
See Also: PatternMatcher AwkCompiler
Constructor Summary | |
---|---|
AwkMatcher() |
Method Summary | |
---|---|
boolean | contains(char[] input, Pattern pattern)
Determines if a string (represented as a char[]) contains a pattern.
|
boolean | contains(String input, Pattern pattern)
Determines if a string contains a pattern. |
boolean | contains(PatternMatcherInput input, Pattern pattern)
Determines if the contents of a PatternMatcherInput, starting from the
current offset of the input contains a pattern.
|
boolean | contains(AwkStreamInput input, Pattern pattern)
Determines if the contents of an AwkStreamInput, starting from the
current offset of the input contains a pattern.
|
MatchResult | getMatch()
Fetches the last match found by a call to a matches() or contains()
method.
|
boolean | matches(char[] input, Pattern pattern)
Determines if a string (represented as a char[]) exactly
matches a given pattern. |
boolean | matches(String input, Pattern pattern)
Determines if a string exactly matches a given pattern. |
boolean | matches(PatternMatcherInput input, Pattern pattern)
Determines if the contents of a PatternMatcherInput instance
exactly matches a given pattern. |
boolean | matchesPrefix(char[] input, Pattern pattern, int offset)
Determines if a prefix of a string (represented as a char[])
matches a given pattern, starting from a given offset into the string.
|
boolean | matchesPrefix(char[] input, Pattern pattern)
Determines if a prefix of a string (represented as a char[])
matches a given pattern.
|
boolean | matchesPrefix(String input, Pattern pattern)
Determines if a prefix of a string matches a given pattern.
|
boolean | matchesPrefix(PatternMatcherInput input, Pattern pattern)
Determines if a prefix of a PatternMatcherInput instance
matches a given pattern. |
The pattern must be an AwkPattern instance, otherwise a ClassCastException will be thrown. You are not required to, and indeed should NOT try to (for performance reasons), catch a ClassCastException because it will never be thrown as long as you use an AwkPattern as the pattern parameter.
Parameters: input The char[] to test for a match. pattern The AwkPattern to be matched.
Returns: True if the input contains a pattern match, false otherwise.
Throws: ClassCastException If a Pattern instance other than an AwkPattern is passed as the pattern parameter.
The pattern must be an AwkPattern instance, otherwise a ClassCastException will be thrown. You are not required to, and indeed should NOT try to (for performance reasons), catch a ClassCastException because it will never be thrown as long as you use an AwkPattern as the pattern parameter.
Parameters: input The String to test for a match. pattern The AwkPattern to be matched.
Returns: True if the input contains a pattern match, false otherwise.
Throws: ClassCastException If a Pattern instance other than an AwkPattern is passed as the pattern parameter.
PatternMatcherInput
for more details.
As a side effect, if a match is found, the PatternMatcherInput match
offset information is updated. See the PatternMatcherInput
setMatchOffsets(int, int)
method for more details.
The pattern must be an AwkPattern instance, otherwise a ClassCastException will be thrown. You are not required to, and indeed should NOT try to (for performance reasons), catch a ClassCastException because it will never be thrown as long as you use an AwkPattern as the pattern parameter.
This method is usually used in a loop as follows:
PatternMatcher matcher; PatternCompiler compiler; Pattern pattern; PatternMatcherInput input; MatchResult result; compiler = new AwkCompiler(); matcher = new AwkMatcher(); try { pattern = compiler.compile(somePatternString); } catch(MalformedPatternException e) { System.err.println("Bad pattern."); System.err.println(e.getMessage()); return; } input = new PatternMatcherInput(someStringInput); while(matcher.contains(input, pattern)) { result = matcher.getMatch(); // Perform whatever processing on the result you want. }
Parameters: input The PatternMatcherInput to test for a match. pattern The Pattern to be matched.
Returns: True if the input contains a pattern match, false otherwise.
Throws: ClassCastException If a Pattern instance other than an AwkPattern is passed as the pattern parameter.
Note, patterns matching the null string do NOT match at end of input stream. This is different from the behavior you get from the other contains() methods.
The pattern must be an AwkPattern instance, otherwise a ClassCastException will be thrown. You are not required to, and indeed should NOT try to (for performance reasons), catch a ClassCastException because it will never be thrown as long as you use an AwkPattern as the pattern parameter.
This method is usually used in a loop as follows:
PatternMatcher matcher; PatternCompiler compiler; Pattern pattern; AwkStreamInput input; MatchResult result; compiler = new AwkCompiler(); matcher = new AwkMatcher(); try { pattern = compiler.compile(somePatternString); } catch(MalformedPatternException e) { System.err.println("Bad pattern."); System.err.println(e.getMessage()); return; } input = new AwkStreamInput( new BufferedInputStream(new FileInputStream(someFileName))); while(matcher.contains(input, pattern)) { result = matcher.getMatch(); // Perform whatever processing on the result you want. }
Parameters: input The PatternStreamInput to test for a match. pattern The Pattern to be matched.
Returns: True if the input contains a pattern match, false otherwise.
Throws: ClassCastException If a Pattern instance other than an AwkPattern is passed as the pattern parameter.
Returns: A MatchResult instance containing the pattern match found by the last call to any one of the matches() or contains() methods. If no match was found by the last call, returns null.
Parameters: input The char[] to test for an exact match. pattern The AwkPattern to be matched.
Returns: True if input matches pattern, false otherwise.
Throws: ClassCastException If a Pattern instance other than an AwkPattern is passed as the pattern parameter.
Parameters: input The String to test for an exact match. pattern The AwkPattern to be matched.
Returns: True if input matches pattern, false otherwise.
Throws: ClassCastException If a Pattern instance other than an AwkPattern is passed as the pattern parameter.
The pattern must be an AwkPattern instance, otherwise a ClassCastException will be thrown. You are not required to, and indeed should NOT try to (for performance reasons), catch a ClassCastException because it will never be thrown as long as you use an AwkPattern as the pattern parameter.
Parameters: input The PatternMatcherInput to test for a match. pattern The AwkPattern to be matched.
Returns: True if input matches pattern, false otherwise.
Throws: ClassCastException If a Pattern instance other than an AwkPattern is passed as the pattern parameter.
This method is useful for certain common token identification tasks that are made more difficult without this functionality.
Parameters: input The char[] to test for a prefix match. pattern The Pattern to be matched. offset The offset at which to start searching for the prefix.
Returns: True if input matches pattern, false otherwise.
This method is useful for certain common token identification tasks that are made more difficult without this functionality.
Parameters: input The char[] to test for a prefix match. pattern The Pattern to be matched.
Returns: True if input matches pattern, false otherwise.
This method is useful for certain common token identification tasks that are made more difficult without this functionality.
Parameters: input The String to test for a prefix match. pattern The Pattern to be matched.
Returns: True if input matches pattern, false otherwise.
This method is useful for certain common token identification tasks that are made more difficult without this functionality.
Parameters: input The PatternMatcherInput to test for a prefix match. pattern The Pattern to be matched.
Returns: True if input matches pattern, false otherwise.