Source code: com/memoire/re/RETokenChar.java
1
2
3 package com.memoire.re;
4 import com.memoire.re.*;
5
6 /*
7 * gnu/regexp/RETokenChar.java
8 * Copyright (C) 1998 Wes Biggs
9 *
10 * This library is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Library General Public License as published
12 * by the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * You should have received a copy of the GNU Library General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25
26
27 class RETokenChar extends REToken {
28 private char[] ch;
29 private boolean insens;
30
31 RETokenChar(int f_subIndex, char c, boolean ins) {
32 super(f_subIndex);
33 ch = new char [1];
34 ch[0] = (insens = ins) ? Character.toLowerCase(c) : c;
35 }
36
37 int getMinimumLength() {
38 return ch.length;
39 }
40
41 int[] match(RECharIndexed input, int index, int eflags, REMatch mymatch) {
42 int z = ch.length;
43 char c;
44 for (int i=0; i<z; i++) {
45 c = input.charAt(index+i);
46 if (( (insens) ? Character.toLowerCase(c) : c ) != ch[i]) return null;
47 }
48 return next(input,index+z,eflags,mymatch);
49 }
50
51 // Overrides REToken.chain() to optimize for strings
52 boolean chain(REToken next) {
53 if (next instanceof RETokenChar) {
54 RETokenChar cnext = (RETokenChar) next;
55 // assume for now that next can only be one character
56 int newsize = ch.length + cnext.ch.length;
57
58 char[] chTemp = new char [newsize];
59
60 System.arraycopy(ch,0,chTemp,0,ch.length);
61 System.arraycopy(cnext.ch,0,chTemp,ch.length,cnext.ch.length);
62
63 ch = chTemp;
64 return false;
65 } else return super.chain(next);
66 }
67
68 void dump(StringBuffer os) {
69 os.append(ch);
70 }
71 }
72
73