01: /*
02: * gnu/regexp/RETokenStart.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:
20: package gnu.regexp;
21:
22: class RETokenStart extends REToken {
23: private String newline; // matches after a newline
24:
25: RETokenStart(int subIndex, String newline) {
26: super (subIndex);
27: this .newline = newline;
28: }
29:
30: boolean match(CharIndexed input, REMatch mymatch) {
31: // charAt(index-n) may be unknown on a Reader/InputStream. FIXME
32: // Match after a newline if in multiline mode
33:
34: if (newline != null) {
35: int len = newline.length();
36: if (mymatch.offset >= len) {
37: boolean found = true;
38: char z;
39: int i = 0; // position in REToken.newline
40: char ch = input.charAt(mymatch.index - len);
41: do {
42: z = newline.charAt(i);
43: if (ch != z) {
44: found = false;
45: break;
46: }
47: ++i;
48: ch = input.charAt(mymatch.index - len + i);
49: } while (i < len);
50:
51: if (found)
52: return next(input, mymatch);
53: }
54: }
55:
56: // Don't match at all if REG_NOTBOL is set.
57: if ((mymatch.eflags & RE.REG_NOTBOL) > 0)
58: return false;
59:
60: if ((mymatch.eflags & RE.REG_ANCHORINDEX) > 0)
61: return (mymatch.anchor == mymatch.offset) ? next(input,
62: mymatch) : false;
63: else
64: return ((mymatch.index == 0) && (mymatch.offset == 0)) ? next(
65: input, mymatch)
66: : false;
67: }
68:
69: void dump(StringBuffer os) {
70: os.append('^');
71: }
72: }
|