01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /**
19: * @author Nikolay A. Kuznetsov
20: * @version $Revision: 1.10.2.2 $
21: */package java.util.regex;
22:
23: /**
24: * Base class for nodes representing leaf tokens of the RE, those who consumes
25: * fixed number of characters.
26: *
27: * @author Nikolay A. Kuznetsov
28: * @version $Revision: 1.10.2.2 $
29: */
30: abstract class LeafSet extends AbstractSet {
31:
32: protected int charCount = 1;
33:
34: public LeafSet(AbstractSet next) {
35: super (next);
36: setType(AbstractSet.TYPE_LEAF);
37: }
38:
39: public LeafSet() {
40: }
41:
42: /**
43: * Returns "shift", the number of accepted chars commonly internal function,
44: * but called by quantifiers.
45: */
46: public abstract int accepts(int stringIndex, CharSequence testString);
47:
48: /**
49: * Checks if we can enter this state and pass the control to the next one.
50: * Return positive value if match succeeds, negative otherwise.
51: */
52: public int matches(int stringIndex, CharSequence testString,
53: MatchResultImpl matchResult) {
54:
55: if (stringIndex + charCount() > matchResult.getRightBound()) {
56: matchResult.hitEnd = true;
57: return -1;
58: }
59:
60: int shift = accepts(stringIndex, testString);
61: if (shift < 0) {
62: return -1;
63: }
64:
65: return next.matches(stringIndex + shift, testString,
66: matchResult);
67: }
68:
69: /**
70: * Returns number of characters this node consumes.
71: * @return number of characters this node consumes.
72: */
73: public int charCount() {
74: return charCount;
75: }
76:
77: public boolean hasConsumed(MatchResultImpl mr) {
78: return true;
79: }
80: }
|