2 * gnu/regexp/RETokenPOSIX.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 RETokenPOSIX extends REToken {
27 static final int ALNUM = 0;
28 static final int ALPHA = 1;
29 static final int BLANK = 2;
30 static final int CNTRL = 3;
31 static final int DIGIT = 4;
32 static final int GRAPH = 5;
33 static final int LOWER = 6;
34 static final int PRINT = 7;
35 static final int PUNCT = 8;
36 static final int SPACE = 9;
37 static final int UPPER = 10;
38 static final int XDIGIT = 11;
40 // Array indices correspond to constants defined above.
41 static final String[] s_nameTable = {
42 "alnum", "alpha", "blank", "cntrl", "digit", "graph", "lower",
43 "print", "punct", "space", "upper", "xdigit"
46 // The RE constructor uses this to look up the constant for a string
47 static int intValue(String key) {
48 for (int i = 0; i < s_nameTable.length; i++) {
49 if (s_nameTable[i].equals(key)) return i;
54 RETokenPOSIX(int subIndex, int type, boolean insens, boolean negated) {
58 this.negated = negated;
61 int getMinimumLength() {
65 boolean match(CharIndexed input, REMatch mymatch) {
66 char ch = input.charAt(mymatch.index);
67 if (ch == CharIndexed.OUT_OF_BOUNDS)
70 boolean retval = false;
73 // Note that there is some debate over whether '_' should be included
74 retval = Character.isLetterOrDigit(ch) || (ch == '_');
77 retval = Character.isLetter(ch);
80 retval = ((ch == ' ') || (ch == '\t'));
83 retval = Character.isISOControl(ch);
86 retval = Character.isDigit(ch);
89 retval = (!(Character.isWhitespace(ch) || Character.isISOControl(ch)));
92 retval = ((insens && Character.isLetter(ch)) || Character.isLowerCase(ch));
95 retval = (!(Character.isWhitespace(ch) || Character.isISOControl(ch)))
99 // This feels sloppy, especially for non-U.S. locales.
100 retval = ("`~!@#$%^&*()-_=+[]{}\\|;:'\"/?,.<>".indexOf(ch)!=-1);
103 retval = Character.isWhitespace(ch);
106 retval = ((insens && Character.isLetter(ch)) || Character.isUpperCase(ch));
109 retval = (Character.isDigit(ch) || ("abcdefABCDEF".indexOf(ch)!=-1));
113 if (negated) retval = !retval;
116 return next(input, mymatch);
121 void dump(StringBuffer os) {
122 if (negated) os.append('^');
123 os.append("[:" + s_nameTable[type] + ":]");