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: * Greedy quantifier node for the case where there is no intersection with
25: * next node and normal quantifiers could be treated as greedy and possessive.
26: *
27: * @author Nikolay A. Kuznetsov
28: * @version $Revision: 1.8.2.2 $
29: */
30: class UnifiedQuantifierSet extends LeafQuantifierSet {
31:
32: public UnifiedQuantifierSet(LeafSet innerSet, AbstractSet next,
33: int type) {
34: super (innerSet, next, type);
35: }
36:
37: public UnifiedQuantifierSet(LeafQuantifierSet quant) {
38: super ((LeafSet) quant.getInnerSet(), quant.getNext(), quant
39: .getType());
40: innerSet.setNext(this );
41:
42: }
43:
44: public int matches(int stringIndex, CharSequence testString,
45: MatchResultImpl matchResult) {
46: while (stringIndex + leaf.charCount() <= matchResult
47: .getRightBound()
48: && leaf.accepts(stringIndex, testString) > 0)
49: stringIndex += leaf.charCount();
50:
51: return next.matches(stringIndex, testString, matchResult);
52: }
53:
54: public int find(int stringIndex, CharSequence testString,
55: MatchResultImpl matchResult) {
56: int startSearch = next.find(stringIndex, testString,
57: matchResult);
58: if (startSearch < 0)
59: return -1;
60: int newSearch = startSearch - leaf.charCount();
61: while (newSearch >= stringIndex
62: && leaf.accepts(newSearch, testString) > 0) {
63: startSearch = newSearch;
64: newSearch -= leaf.charCount();
65: }
66:
67: return startSearch;
68: }
69: }
|