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