001/*
002 *  gnu/regexp/RETokenRange.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 RETokenRange extends REToken {
023  private char lo, hi;
024  private boolean insens;
025
026  RETokenRange(int subIndex, char lo, char hi, boolean ins) {
027    super(subIndex);
028    this.lo = (insens = ins) ? Character.toLowerCase(lo) : lo;
029    this.hi = ins ? Character.toLowerCase(hi) : hi;
030  }
031
032  int getMinimumLength() {
033    return 1;
034  }
035
036    boolean match(CharIndexed input, REMatch mymatch) {
037        char c = input.charAt(mymatch.index);
038        if (c == CharIndexed.OUT_OF_BOUNDS) return false;
039        if (insens) c = Character.toLowerCase(c);
040        if ((c >= lo) && (c <= hi)) {
041            ++mymatch.index;
042            return next(input, mymatch);
043        }
044        return false;
045    }
046    
047  void dump(StringBuffer os) {
048    os.append(lo).append('-').append(hi);
049  }
050}
051