01: /*
02: * gnu/regexp/CharIndexed.java
03: * Copyright (C) 1998-2001 Wes Biggs
04: *
05: * This library is free software; you can redistribute it and/or modify
06: * it under the terms of the GNU Lesser General Public License as published
07: * by the Free Software Foundation; either version 2.1 of the License, or
08: * (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: * GNU Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public License
16: * along with this program; if not, write to the Free Software
17: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18: */
19: package gnu.regexp;
20:
21: /**
22: * Defines the interface used internally so that different types of source
23: * text can be accessed in the same way. Built-in concrete classes provide
24: * support for String, StringBuffer, InputStream and char[] types.
25: * A class that is CharIndexed supports the notion of a cursor within a
26: * block of text. The cursor must be able to be advanced via the move()
27: * method. The charAt() method returns the character at the cursor position
28: * plus a given offset.
29: *
30: * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
31: */
32: public interface CharIndexed {
33: /**
34: * Defines a constant (0xFFFF was somewhat arbitrarily chosen)
35: * that can be returned by the charAt() function indicating that
36: * the specified index is out of range.
37: */
38: char OUT_OF_BOUNDS = '\uFFFF';
39:
40: /**
41: * Returns the character at the given offset past the current cursor
42: * position in the input. The index of the current position is zero.
43: * It is possible for this method to be called with a negative index.
44: * This happens when using the '^' operator in multiline matching mode
45: * or the '\b' or '\<' word boundary operators. In any case, the lower
46: * bound is currently fixed at -2 (for '^' with a two-character newline).
47: *
48: * @param index the offset position in the character field to examine
49: * @return the character at the specified index, or the OUT_OF_BOUNDS
50: * character defined by this interface.
51: */
52: char charAt(int index);
53:
54: /**
55: * Shifts the input buffer by a given number of positions. Returns
56: * true if the new cursor position is valid.
57: */
58: boolean move(int index);
59:
60: /**
61: * Returns true if the most recent move() operation placed the cursor
62: * position at a valid position in the input.
63: */
64: boolean isValid();
65: }
|