001/*
002 *  gnu/regexp/CharIndexed.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;
020
021/**
022 * Defines the interface used internally so that different types of source
023 * text can be accessed in the same way.  Built-in concrete classes provide
024 * support for String, StringBuffer, InputStream and char[] types.
025 * A class that is CharIndexed supports the notion of a cursor within a
026 * block of text.  The cursor must be able to be advanced via the move()
027 * method.  The charAt() method returns the character at the cursor position
028 * plus a given offset.
029 *
030 * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
031 */
032public interface CharIndexed {
033    /**
034     * Defines a constant (0xFFFF was somewhat arbitrarily chosen)
035     * that can be returned by the charAt() function indicating that
036     * the specified index is out of range.
037     */
038    char OUT_OF_BOUNDS = '\uFFFF';
039
040    /**
041     * Returns the character at the given offset past the current cursor
042     * position in the input.  The index of the current position is zero.
043     * It is possible for this method to be called with a negative index.
044     * This happens when using the '^' operator in multiline matching mode
045     * or the '\b' or '\<' word boundary operators.  In any case, the lower
046     * bound is currently fixed at -2 (for '^' with a two-character newline).
047     *
048     * @param index the offset position in the character field to examine
049     * @return the character at the specified index, or the OUT_OF_BOUNDS
050     *   character defined by this interface.
051     */
052    char charAt(int index);
053
054    /**
055     * Shifts the input buffer by a given number of positions.  Returns
056     * true if the new cursor position is valid.
057     */
058    boolean move(int index);
059
060    /**
061     * Returns true if the most recent move() operation placed the cursor
062     * position at a valid position in the input.
063     */
064    boolean isValid();
065}