01: /*
02: * gnu/regexp/RETokenChar.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 RETokenChar extends REToken {
23: private char[] ch;
24: private boolean insens;
25:
26: RETokenChar(int f_subIndex, char c, boolean ins) {
27: super (f_subIndex);
28: ch = new char[1];
29: ch[0] = (insens = ins) ? Character.toLowerCase(c) : c;
30: }
31:
32: int getMinimumLength() {
33: return ch.length;
34: }
35:
36: int[] match(CharIndexed input, int index, int eflags,
37: REMatch mymatch) {
38: int z = ch.length;
39: char c;
40: for (int i = 0; i < z; i++) {
41: c = input.charAt(index + i);
42: if (((insens) ? Character.toLowerCase(c) : c) != ch[i])
43: return null;
44: }
45: return next(input, index + z, eflags, mymatch);
46: }
47:
48: // Overrides REToken.chain() to optimize for strings
49: boolean chain(REToken next) {
50: if (next instanceof RETokenChar) {
51: RETokenChar cnext = (RETokenChar) next;
52: // assume for now that next can only be one character
53: int newsize = ch.length + cnext.ch.length;
54:
55: char[] chTemp = new char[newsize];
56:
57: System.arraycopy(ch, 0, chTemp, 0, ch.length);
58: System.arraycopy(cnext.ch, 0, chTemp, ch.length,
59: cnext.ch.length);
60:
61: ch = chTemp;
62: return false;
63: } else
64: return super .chain(next);
65: }
66:
67: void dump(StringBuffer os) {
68: os.append(ch);
69: }
70: }
|