OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [gnu/] [regexp/] [RETokenPOSIX.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* gnu/regexp/RETokenPOSIX.java
2
   Copyright (C) 1998-2001, 2004 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
 
39
package gnu.regexp;
40
 
41
final class RETokenPOSIX extends REToken {
42
  int type;
43
  boolean insens;
44
  boolean negated;
45
 
46
  static final int  ALNUM = 0;
47
  static final int  ALPHA = 1;
48
  static final int  BLANK = 2;
49
  static final int  CNTRL = 3;
50
  static final int  DIGIT = 4;
51
  static final int  GRAPH = 5;
52
  static final int  LOWER = 6;
53
  static final int  PRINT = 7;
54
  static final int  PUNCT = 8;
55
  static final int  SPACE = 9;
56
  static final int  UPPER = 10;
57
  static final int XDIGIT = 11;
58
 
59
  // Array indices correspond to constants defined above.
60
  static final String[] s_nameTable =  {
61
    "alnum", "alpha", "blank", "cntrl", "digit", "graph", "lower",
62
    "print", "punct", "space", "upper", "xdigit"
63
  };
64
 
65
  // The RE constructor uses this to look up the constant for a string
66
  static int intValue(String key) {
67
    for (int i = 0; i < s_nameTable.length; i++) {
68
      if (s_nameTable[i].equals(key)) return i;
69
    }
70
    return -1;
71
  }
72
 
73
  RETokenPOSIX(int subIndex, int type, boolean insens, boolean negated) {
74
    super(subIndex);
75
    this.type = type;
76
    this.insens = insens;
77
    this.negated = negated;
78
  }
79
 
80
    int getMinimumLength() {
81
        return 1;
82
    }
83
 
84
    int getMaximumLength() {
85
        return 1;
86
    }
87
 
88
    boolean match(CharIndexed input, REMatch mymatch) {
89
    char ch = input.charAt(mymatch.index);
90
    if (ch == CharIndexed.OUT_OF_BOUNDS)
91
      return false;
92
 
93
    boolean retval = false;
94
    switch (type) {
95
    case ALNUM:
96
        // Note that there is some debate over whether '_' should be included
97
        retval = Character.isLetterOrDigit(ch) || (ch == '_');
98
        break;
99
    case ALPHA:
100
        retval = Character.isLetter(ch);
101
        break;
102
    case BLANK:
103
        retval = ((ch == ' ') || (ch == '\t'));
104
        break;
105
    case CNTRL:
106
        retval = Character.isISOControl(ch);
107
        break;
108
    case DIGIT:
109
        retval = Character.isDigit(ch);
110
        break;
111
    case GRAPH:
112
        retval = (!(Character.isWhitespace(ch) || Character.isISOControl(ch)));
113
        break;
114
    case LOWER:
115
        retval = ((insens && Character.isLetter(ch)) || Character.isLowerCase(ch));
116
        break;
117
    case PRINT:
118
        retval = (!(Character.isWhitespace(ch) || Character.isISOControl(ch)))
119
            || (ch == ' ');
120
        break;
121
    case PUNCT:
122
        // This feels sloppy, especially for non-U.S. locales.
123
        retval = ("`~!@#$%^&*()-_=+[]{}\\|;:'\"/?,.<>".indexOf(ch)!=-1);
124
        break;
125
    case SPACE:
126
        retval = Character.isWhitespace(ch);
127
        break;
128
    case UPPER:
129
        retval = ((insens && Character.isLetter(ch)) || Character.isUpperCase(ch));
130
        break;
131
    case XDIGIT:
132
        retval = (Character.isDigit(ch) || ("abcdefABCDEF".indexOf(ch)!=-1));
133
        break;
134
    }
135
 
136
    if (negated) retval = !retval;
137
    if (retval) {
138
        ++mymatch.index;
139
        return next(input, mymatch);
140
    }
141
    else return false;
142
  }
143
 
144
  void dump(StringBuffer os) {
145
    if (negated) os.append('^');
146
    os.append("[:" + s_nameTable[type] + ":]");
147
  }
148
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.