Package org.apache.oro.text.regex
Class Perl5MatchResult
- java.lang.Object
-
- org.apache.oro.text.regex.Perl5MatchResult
-
- All Implemented Interfaces:
MatchResult
final class Perl5MatchResult extends java.lang.Object implements MatchResult
A class used to store and access the results of a Perl5Pattern match.- Since:
- 1.0
- See Also:
PatternMatcher,Perl5Matcher
-
-
Field Summary
Fields Modifier and Type Field Description (package private) int[]_beginGroupOffsetArrays containing the beginning and end offsets of the pattern groups matched within the actual matched pattern contained in the variablematch.(package private) int[]_endGroupOffsetArrays containing the beginning and end offsets of the pattern groups matched within the actual matched pattern contained in the variablematch.(package private) java.lang.String_matchThe entire string that matched the pattern.(package private) int_matchBeginOffsetThe character offset into the line or stream where the match begins.
-
Constructor Summary
Constructors Constructor Description Perl5MatchResult(int groups)Constructs a MatchResult able to store match information for a number of subpattern groups.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intbegin(int group)intbeginOffset(int group)Returns an offset marking the beginning of the pattern match relative to the beginning of the input.intend(int group)intendOffset(int group)Returns an offset marking the end of the pattern match relative to the beginning of the input.java.lang.Stringgroup(int group)Returns the contents of the parenthesized subgroups of a match, counting parentheses from left to right and starting from 1.intgroups()intlength()A convenience method returning the length of the entire match.java.lang.StringtoString()The same as group(0).
-
-
-
Field Detail
-
_matchBeginOffset
int _matchBeginOffset
The character offset into the line or stream where the match begins. Pattern matching methods that look for matches a line at a time should use this field as the offset into the line of the match. Methods that look for matches independent of line boundaries should use this field as the offset into the entire text stream.
-
_beginGroupOffset
int[] _beginGroupOffset
Arrays containing the beginning and end offsets of the pattern groups matched within the actual matched pattern contained in the variablematch. Pattern matching methods that do not match subgroups, will only contain entries for group 0, which always refers to the entire pattern.beginGroupOffsetcontains the start offset of the groups, indexed by group number, which will always be 0 for group 0.endGroupOffsetcontains the ending offset + 1 of the groups. A group matching the null string will havebeginGroupOffsetandendGroupOffsetentries of equal value. Following a convention established by the GNU regular expression library for the C language, groups that are not part of a match contain -1 as their begin and end offsets.
-
_endGroupOffset
int[] _endGroupOffset
Arrays containing the beginning and end offsets of the pattern groups matched within the actual matched pattern contained in the variablematch. Pattern matching methods that do not match subgroups, will only contain entries for group 0, which always refers to the entire pattern.beginGroupOffsetcontains the start offset of the groups, indexed by group number, which will always be 0 for group 0.endGroupOffsetcontains the ending offset + 1 of the groups. A group matching the null string will havebeginGroupOffsetandendGroupOffsetentries of equal value. Following a convention established by the GNU regular expression library for the C language, groups that are not part of a match contain -1 as their begin and end offsets.
-
_match
java.lang.String _match
The entire string that matched the pattern.
-
-
Constructor Detail
-
Perl5MatchResult
Perl5MatchResult(int groups)
Constructs a MatchResult able to store match information for a number of subpattern groups.- Parameters:
groups- The number of groups this MatchResult can store. Only postitive values greater than or equal to 1 make any sense. At minimum, a MatchResult stores one group which represents the entire pattern matched including all subparts.
-
-
Method Detail
-
length
public int length()
Description copied from interface:MatchResultA convenience method returning the length of the entire match. If you want to get the length of a particular subgroup you should use theMatchResult.group(int)method to get the string and then access its length() method as follows:
The length() method serves as a more a more efficient way to do:int length = -1; // Use -1 to indicate group doesn't exist MatchResult result; String subgroup; // Initialization of result omitted subgroup = result.group(1); if(subgroup != null) length = subgroup.length();
length = result.group(0).length();
- Specified by:
lengthin interfaceMatchResult- Returns:
- The length of the match.
-
groups
public int groups()
- Specified by:
groupsin interfaceMatchResult- Returns:
- The number of groups contained in the result. This number includes the 0th group. In other words, the result refers to the number of parenthesized subgroups plus the entire match itself.
-
group
public java.lang.String group(int group)
Description copied from interface:MatchResultReturns the contents of the parenthesized subgroups of a match, counting parentheses from left to right and starting from 1. Group 0 always refers to the entire match. For example, if the patternfoo(\d+)is used to extract a match from the inputabfoo123, thengroup(0)will returnfoo123andgroup(1)will return123.group(2)will returnnullbecause there is only one subgroup in the original pattern.- Specified by:
groupin interfaceMatchResult- Parameters:
group- The pattern subgroup to return.- Returns:
- A string containing the indicated pattern subgroup. Group 0 always refers to the entire match. If a group was never matched, it returns null. This is not to be confused with a group matching the null string, which will return a String of length 0.
-
begin
public int begin(int group)
- Specified by:
beginin interfaceMatchResult- Parameters:
group- The pattern subgroup.- Returns:
- The offset into group 0 of the first token in the indicated pattern subgroup. If a group was never matched or does not exist, returns -1.
-
end
public int end(int group)
- Specified by:
endin interfaceMatchResult- Parameters:
group- The pattern subgroup.- Returns:
- Returns one plus the offset into group 0 of the last token in the indicated pattern subgroup. If a group was never matched or does not exist, returns -1. A group matching the null string will return its start offset.
-
beginOffset
public int beginOffset(int group)
Returns an offset marking the beginning of the pattern match relative to the beginning of the input.- Specified by:
beginOffsetin interfaceMatchResult- Parameters:
group- The pattern subgroup.- Returns:
- The offset of the first token in the indicated pattern subgroup. If a group was never matched or does not exist, returns -1.
-
endOffset
public int endOffset(int group)
Returns an offset marking the end of the pattern match relative to the beginning of the input.- Specified by:
endOffsetin interfaceMatchResult- Parameters:
group- The pattern subgroup.- Returns:
- Returns one plus the offset of the last token in the indicated pattern subgroup. If a group was never matched or does not exist, returns -1. A group matching the null string will return its start offset.
-
toString
public java.lang.String toString()
The same as group(0).- Specified by:
toStringin interfaceMatchResult- Overrides:
toStringin classjava.lang.Object- Returns:
- A string containing the entire match.
-
-