01: /*
02: * gnu/regexp/RETokenOneOf.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: * @since gnu.regexp 1.1.3
23: * @author Shashank Bapat
24: */
25: final class RETokenLookAhead extends REToken {
26: REToken re;
27: boolean negative;
28:
29: RETokenLookAhead(REToken re, boolean negative) throws REException {
30: super (0);
31: this .re = re;
32: this .negative = negative;
33: }
34:
35: boolean match(CharIndexed input, REMatch mymatch) {
36: REMatch trymatch = (REMatch) mymatch.clone();
37: REMatch trymatch1 = (REMatch) mymatch.clone();
38: REMatch newMatch = null;
39: if (re.match(input, trymatch)) {
40: if (negative)
41: return false;
42: if (next(input, trymatch1))
43: newMatch = trymatch1;
44: }
45:
46: if (newMatch != null) {
47: if (negative)
48: return false;
49: //else
50: mymatch.assignFrom(newMatch);
51: return true;
52: } else { // no match
53: if (negative)
54: return next(input, mymatch);
55: //else
56: return false;
57: }
58: }
59:
60: void dump(StringBuffer os) {
61: os.append("(?");
62: os.append(negative ? '!' : '=');
63: re.dumpAll(os);
64: os.append(')');
65: }
66: }
|