1 19 20 package gnu.regexp; 21 22 final class RETokenPOSIX extends REToken { 23 int type; 24 boolean insens; 25 boolean negated; 26 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; 39 40 static final String [] s_nameTable = { 42 "alnum", "alpha", "blank", "cntrl", "digit", "graph", "lower", 43 "print", "punct", "space", "upper", "xdigit" 44 }; 45 46 static int intValue(String key) { 48 for (int i = 0; i < s_nameTable.length; i++) { 49 if (s_nameTable[i].equals(key)) return i; 50 } 51 return -1; 52 } 53 54 RETokenPOSIX(int subIndex, int type, boolean insens, boolean negated) { 55 super(subIndex); 56 this.type = type; 57 this.insens = insens; 58 this.negated = negated; 59 } 60 61 int getMinimumLength() { 62 return 1; 63 } 64 65 boolean match(CharIndexed input, REMatch mymatch) { 66 char ch = input.charAt(mymatch.index); 67 if (ch == CharIndexed.OUT_OF_BOUNDS) 68 return false; 69 70 boolean retval = false; 71 switch (type) { 72 case ALNUM: 73 retval = Character.isLetterOrDigit(ch) || (ch == '_'); 75 break; 76 case ALPHA: 77 retval = Character.isLetter(ch); 78 break; 79 case BLANK: 80 retval = ((ch == ' ') || (ch == '\t')); 81 break; 82 case CNTRL: 83 retval = Character.isISOControl(ch); 84 break; 85 case DIGIT: 86 retval = Character.isDigit(ch); 87 break; 88 case GRAPH: 89 retval = (!(Character.isWhitespace(ch) || Character.isISOControl(ch))); 90 break; 91 case LOWER: 92 retval = ((insens && Character.isLetter(ch)) || Character.isLowerCase(ch)); 93 break; 94 case PRINT: 95 retval = (!(Character.isWhitespace(ch) || Character.isISOControl(ch))) 96 || (ch == ' '); 97 break; 98 case PUNCT: 99 retval = ("`~!@#$%^&*()-_=+[]{}\\|;:'\"/?,.<>".indexOf(ch)!=-1); 101 break; 102 case SPACE: 103 retval = Character.isWhitespace(ch); 104 break; 105 case UPPER: 106 retval = ((insens && Character.isLetter(ch)) || Character.isUpperCase(ch)); 107 break; 108 case XDIGIT: 109 retval = (Character.isDigit(ch) || ("abcdefABCDEF".indexOf(ch)!=-1)); 110 break; 111 } 112 113 if (negated) retval = !retval; 114 if (retval) { 115 ++mymatch.index; 116 return next(input, mymatch); 117 } 118 else return false; 119 } 120 121 void dump(StringBuffer os) { 122 if (negated) os.append('^'); 123 os.append("[:" + s_nameTable[type] + ":]"); 124 } 125 } 126 | Popular Tags |