001/*
002 *  gnu/regexp/CharIndexedStringBuffer.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 */
019package gnu.regexp;
020import java.io.Serializable;
021
022class CharIndexedStringBuffer implements CharIndexed, Serializable {
023    private StringBuffer s;
024    private int anchor;
025
026    CharIndexedStringBuffer(StringBuffer str, int index) {
027        s = str;
028        anchor = index;
029    }
030
031  public char charAt(int index) {
032      int pos = anchor + index;
033    return ((pos < s.length()) && (pos >= 0)) ? s.charAt(pos) : OUT_OF_BOUNDS;
034  }
035
036  public boolean isValid() {
037    return (anchor < s.length());
038  }
039
040  public boolean move(int index) {
041    return ((anchor += index) < s.length());
042  }
043}