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.9.2.2 $
21: */package java.util.regex;
22:
23: /**
24: * Reluctant version of composite (i.e. {n,m}) quantifier node over
25: * group.
26: *
27: * @author Nikolay A. Kuznetsov
28: * @version $Revision: 1.9.2.2 $
29: */
30: class RelCompositeGroupQuantifierSet extends
31: CompositeGroupQuantifierSet {
32:
33: public RelCompositeGroupQuantifierSet(Quantifier quant,
34: AbstractSet innerSet, AbstractSet next, int type,
35: int setCounter) {
36: super (quant, innerSet, next, type, setCounter);
37: }
38:
39: public int matches(int stringIndex, CharSequence testString,
40: MatchResultImpl matchResult) {
41: int enterCounter = matchResult.getEnterCounter(setCounter);
42:
43: if (!innerSet.hasConsumed(matchResult))
44: return next.matches(stringIndex, testString, matchResult);
45:
46: // can't go inner set;
47: if (enterCounter >= quantifier.max()) {
48: matchResult.setEnterCounter(setCounter, 0);
49: return next.matches(stringIndex, testString, matchResult);
50: }
51:
52: int nextIndex;
53:
54: if (enterCounter >= quantifier.min()) {
55: nextIndex = next.matches(stringIndex, testString,
56: matchResult);
57: if (nextIndex < 0) {
58: matchResult.setEnterCounter(setCounter, ++enterCounter);
59: nextIndex = innerSet.matches(stringIndex, testString,
60: matchResult);
61: } else {
62: matchResult.setEnterCounter(setCounter, 0);
63: return nextIndex;
64: }
65: } else {
66: matchResult.setEnterCounter(setCounter, ++enterCounter);
67: nextIndex = innerSet.matches(stringIndex, testString,
68: matchResult);
69: }
70:
71: return nextIndex;
72: }
73: }
|