001/*
002 *  gnu/regexp/RETokenBackRef.java
003 *  Copyright (C) 1998-2001 Wes Biggs
004 *
005 *  This library is free software; you can redistribute it and/or modify
006 *  it under the terms of the GNU Lesser General Public License as published
007 *  by the Free Software Foundation; either version 2.1 of the License, or
008 *  (at your option) any later version.
009 *
010 *  This library is distributed in the hope that it will be useful,
011 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
012 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 *  GNU Lesser General Public License for more details.
014 *
015 *  You should have received a copy of the GNU Lesser General Public License
016 *  along with this program; if not, write to the Free Software
017 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
018 */
019
020package gnu.regexp;
021
022final class RETokenBackRef extends REToken {
023  private int num;
024  private boolean insens;
025  
026  RETokenBackRef(int subIndex, int num, boolean insens) {
027    super(subIndex);
028    this.num = num;
029    this.insens = insens;
030  }
031
032  // should implement getMinimumLength() -- any ideas?
033
034    boolean match(CharIndexed input, REMatch mymatch) {
035        int b,e;
036        b = mymatch.start[num];
037        e = mymatch.end[num];
038        if ((b==-1)||(e==-1)) return false; // this shouldn't happen, but...
039        for (int i=b; i<e; i++) {
040            if (input.charAt(mymatch.index+i-b) != input.charAt(i)) {
041                return false;
042            }
043        }
044        mymatch.index += e-b;
045        return next(input, mymatch);
046    }
047    
048    void dump(StringBuffer os) {
049        os.append('\\').append(num);
050    }
051}
052
053