FileDocCategorySizeDatePackage
Match.javaAPI DocApache Xerces 3.0.16044Fri Sep 14 20:33:52 BST 2007org.apache.xerces.impl.xpath.regex

Match

public class Match extends Object implements Cloneable
An instance of this class has ranges captured in matching.
xerces.internal
see
RegularExpression#matches(char[], int, int, Match)
see
RegularExpression#matches(char[], Match)
see
RegularExpression#matches(java.text.CharacterIterator, Match)
see
RegularExpression#matches(java.lang.String, int, int, Match)
see
RegularExpression#matches(java.lang.String, Match)
author
TAMURA Kent <kent@trl.ibm.co.jp>
version
$Id: Match.java 446721 2006-09-15 20:35:34Z mrglavas $

Fields Summary
int[]
beginpos
int[]
endpos
int
nofgroups
CharacterIterator
ciSource
String
strSource
char[]
charSource
Constructors Summary
public Match()
Creates an instance.


            
      
    
Methods Summary
public synchronized java.lang.Objectclone()

        Match ma = new Match();
        if (this.nofgroups > 0) {
            ma.setNumberOfGroups(this.nofgroups);
            if (this.ciSource != null)  ma.setSource(this.ciSource);
            if (this.strSource != null)  ma.setSource(this.strSource);
            for (int i = 0;  i < this.nofgroups;  i ++) {
                ma.setBeginning(i, this.getBeginning(i));
                ma.setEnd(i, this.getEnd(i));
            }
        }
        return ma;
    
public intgetBeginning(int index)
Return a start position in the target text matched to specified regular expression group.

param
index Less than getNumberOfGroups().

        if (this.beginpos == null)
            throw new IllegalStateException("A result is not set.");
        if (index < 0 || this.nofgroups <= index)
            throw new IllegalArgumentException("The parameter must be less than "
                                               +this.nofgroups+": "+index);
        return this.beginpos[index];
    
public java.lang.StringgetCapturedText(int index)
Return an substring of the target text matched to specified regular expression group.

param
index Less than getNumberOfGroups().

        if (this.beginpos == null)
            throw new IllegalStateException("match() has never been called.");
        if (index < 0 || this.nofgroups <= index)
            throw new IllegalArgumentException("The parameter must be less than "
                                               +this.nofgroups+": "+index);
        String ret;
        int begin = this.beginpos[index], end = this.endpos[index];
        if (begin < 0 || end < 0)  return null;
        if (this.ciSource != null) {
            ret = REUtil.substring(this.ciSource, begin, end);
        } else if (this.strSource != null) {
            ret = this.strSource.substring(begin, end);
        } else {
            ret = new String(this.charSource, begin, end-begin);
        }
        return ret;
    
public intgetEnd(int index)
Return an end position in the target text matched to specified regular expression group.

param
index Less than getNumberOfGroups().

        if (this.endpos == null)
            throw new IllegalStateException("A result is not set.");
        if (index < 0 || this.nofgroups <= index)
            throw new IllegalArgumentException("The parameter must be less than "
                                               +this.nofgroups+": "+index);
        return this.endpos[index];
    
public intgetNumberOfGroups()
Return the number of regular expression groups. This method returns 1 when the regular expression has no capturing-parenthesis.

        if (this.nofgroups <= 0)
            throw new IllegalStateException("A result is not set.");
        return this.nofgroups;
    
protected voidsetBeginning(int index, int v)

        this.beginpos[index] = v;
    
protected voidsetEnd(int index, int v)

        this.endpos[index] = v;
    
protected voidsetNumberOfGroups(int n)

        int oldn = this.nofgroups;
        this.nofgroups = n;
        if (oldn <= 0
            || oldn < n || n*2 < oldn) {
            this.beginpos = new int[n];
            this.endpos = new int[n];
        }
        for (int i = 0;  i < n;  i ++) {
            this.beginpos[i] = -1;
            this.endpos[i] = -1;
        }
    
protected voidsetSource(java.text.CharacterIterator ci)

        this.ciSource = ci;
        this.strSource = null;
        this.charSource = null;
    
protected voidsetSource(java.lang.String str)

        this.ciSource = null;
        this.strSource = str;
        this.charSource = null;
    
protected voidsetSource(char[] chars)

        this.ciSource = null;
        this.strSource = null;
        this.charSource = chars;