01: /*
02: * gnu/regexp/RETokenStart.java
03: * Copyright (C) 1998 Wes Biggs
04: *
05: * This library is free software; you can redistribute it and/or modify
06: * it under the terms of the GNU Library General Public License as published
07: * by the Free Software Foundation; either version 2 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 Library General Public License for more details.
14: *
15: * You should have received a copy of the GNU Library 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:
20: package gnu.regexp;
21:
22: class RETokenStart extends REToken {
23: private boolean newline; // matches after a newline
24:
25: RETokenStart(int f_subIndex, boolean f_newline) {
26: super (f_subIndex);
27: newline = f_newline;
28: }
29:
30: int[] match(CharIndexed input, int index, int eflags,
31: REMatch mymatch) {
32: // charAt(index-1) may be unknown on an InputStream. FIXME
33: // Match after a newline if in multiline mode
34: if (newline && (mymatch.offset > 0)
35: && (input.charAt(index - 1) == '\n'))
36: return next(input, index, eflags, mymatch);
37:
38: // Don't match at all if REG_NOTBOL is set.
39: if ((eflags & RE.REG_NOTBOL) > 0)
40: return null;
41:
42: if ((eflags & RE.REG_ANCHORINDEX) > 0)
43: return (mymatch.anchor == mymatch.offset) ? next(input,
44: index, eflags, mymatch) : null;
45: else
46: return ((index == 0) && (mymatch.offset == 0)) ? next(
47: input, index, eflags, mymatch) : null;
48: }
49:
50: void dump(StringBuffer os) {
51: os.append('^');
52: }
53: }
|