Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.oro.text.awk
Class AwkMatchResult  view AwkMatchResult download AwkMatchResult.java

java.lang.Object
  extended byorg.apache.oro.text.awk.AwkMatchResult
All Implemented Interfaces:
org.apache.oro.text.regex.MatchResult

final class AwkMatchResult
extends java.lang.Object
implements org.apache.oro.text.regex.MatchResult

A class used to store and access the results of an AwkPattern match. It is important for you to remember that AwkMatcher does not save parenthesized sub-group information. Therefore the number of groups saved in an AwkMatchResult will always be 1.

Since:
1.0
Version:
@version@

Field Summary
private  int __length
          The length of the match.
private  java.lang.String __match
          The entire string that matched the pattern.
private  int __matchBeginOffset
          The character offset into the line or stream where the match begins.
 
Constructor Summary
(package private) AwkMatchResult(java.lang.String match, int matchBeginOffset)
          Default constructor given default access to prevent instantiation outside the package.
 
Method Summary
(package private)  void _incrementMatchBeginOffset(int streamOffset)
          Adjusts the relative offset where the match begins to an absolute value.
 int begin(int group)
           
 int beginOffset(int group)
          Returns an offset marking the beginning of the pattern match relative to the beginning of the input.
 int end(int group)
           
 int endOffset(int group)
          Returns an offset marking the end of the pattern match relative to the beginning of the input.
 java.lang.String group(int group)
          Returns the contents of the parenthesized subgroups of a match, counting parentheses from left to right and starting from 1.
 int groups()
           
 int length()
          A convenience method returning the length of the entire match.
 java.lang.String toString()
          The same as group(0).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

__matchBeginOffset

private 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.


__length

private int __length
The length of the match. Stored as a convenience to avoid calling the String length(). Since groups aren't saved, all we need is the length and the offset into the stream.


__match

private java.lang.String __match
The entire string that matched the pattern.

Constructor Detail

AwkMatchResult

AwkMatchResult(java.lang.String match,
               int matchBeginOffset)
Default constructor given default access to prevent instantiation outside the package.

Method Detail

_incrementMatchBeginOffset

void _incrementMatchBeginOffset(int streamOffset)
Adjusts the relative offset where the match begins to an absolute value. Only used by AwkMatcher to adjust the offset for stream matches.


length

public int length()
Description copied from interface: org.apache.oro.text.regex.MatchResult
A convenience method returning the length of the entire match. If you want to get the length of a particular subgroup you should use the MatchResult.group(int)>MatchResult.group(int) 55 method to get the string and then access its length() method as follows:

 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();

 

The length() method serves as a more a more efficient way to do:

 length = result.group(0).length();
 

Specified by:
length in interface org.apache.oro.text.regex.MatchResult

groups

public int groups()
Specified by:
groups in interface org.apache.oro.text.regex.MatchResult

group

public java.lang.String group(int group)
Description copied from interface: org.apache.oro.text.regex.MatchResult
Returns 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 pattern foo(\d+) is used to extract a match from the input abfoo123 , then group(0) will return foo123 and group(1) will return 123 . group(2) will return null because there is only one subgroup in the original pattern.

Specified by:
group in interface org.apache.oro.text.regex.MatchResult

begin

public int begin(int group)
Specified by:
begin in interface org.apache.oro.text.regex.MatchResult

end

public int end(int group)
Specified by:
end in interface org.apache.oro.text.regex.MatchResult

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:
beginOffset in interface org.apache.oro.text.regex.MatchResult

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:
endOffset in interface org.apache.oro.text.regex.MatchResult

toString

public java.lang.String toString()
The same as group(0).

Specified by:
toString in interface org.apache.oro.text.regex.MatchResult