2 * gnu/regexp/RETokenChar.java
3 * Copyright (C) 1998-2001 Wes Biggs
5 * This library is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation; either version 2.1 of the License, or
8 * (at your option) any later version.
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.
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.
22 final class RETokenChar extends REToken {
24 private boolean insens;
26 RETokenChar(int subIndex, char c, boolean ins) {
29 ch[0] = (insens = ins) ? Character.toLowerCase(c) : c;
32 int getMinimumLength() {
36 boolean match(CharIndexed input, REMatch mymatch) {
39 for (int i=0; i<z; i++) {
40 c = input.charAt(mymatch.index+i);
41 if (( (insens) ? Character.toLowerCase(c) : c ) != ch[i]) {
47 return next(input, mymatch);
50 // Overrides REToken.chain() to optimize for strings
51 boolean chain(REToken next) {
52 if (next instanceof RETokenChar) {
53 RETokenChar cnext = (RETokenChar) next;
54 // assume for now that next can only be one character
55 int newsize = ch.length + cnext.ch.length;
57 char[] chTemp = new char [newsize];
59 System.arraycopy(ch,0,chTemp,0,ch.length);
60 System.arraycopy(cnext.ch,0,chTemp,ch.length,cnext.ch.length);
64 } else return super.chain(next);
67 void dump(StringBuffer os) {