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.8.2.2 $
21: */package java.util.regex;
22:
23: /**
24: * Reluctant version of composite(i.e. {n,m}) quantifier set over leaf nodes.
25: * @author Nikolay A. Kuznetsov
26: * @version $Revision: 1.8.2.2 $
27: */
28: class ReluctantCompositeQuantifierSet extends CompositeQuantifierSet {
29:
30: public ReluctantCompositeQuantifierSet(Quantifier quant,
31: LeafSet innerSet, AbstractSet next, int type) {
32: super (quant, innerSet, next, type);
33: }
34:
35: public int matches(int stringIndex, CharSequence testString,
36: MatchResultImpl matchResult) {
37: int min = quantifier.min();
38: int max = quantifier.max();
39: int i = 0;
40: int shift = 0;
41:
42: for (; i < min; i++) {
43:
44: if (stringIndex + leaf.charCount() > matchResult
45: .getRightBound()) {
46: matchResult.hitEnd = true;
47: return -1;
48: }
49:
50: shift = leaf.accepts(stringIndex, testString);
51: if (shift < 1) {
52: return -1;
53: }
54: stringIndex += shift;
55: }
56:
57: do {
58: shift = next.matches(stringIndex, testString, matchResult);
59: if (shift >= 0) {
60: return shift;
61: }
62:
63: if (stringIndex + leaf.charCount() <= matchResult
64: .getRightBound()) {
65: shift = leaf.accepts(stringIndex, testString);
66: stringIndex += shift;
67: i++;
68: }
69:
70: } while (shift >= 1 && i <= max);
71:
72: return -1;
73: }
74: }
|