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: import org.apache.harmony.regex.internal.nls.Messages;
24:
25: /**
26: * Case Insensitive back reference node;
27: *
28: * @author Nikolay A. Kuznetsov
29: * @version $Revision: 1.8.2.2 $
30: */
31: class CIBackReferenceSet extends JointSet {
32:
33: protected int referencedGroup;
34:
35: protected int consCounter;
36:
37: /**
38: * @param substring
39: */
40: public CIBackReferenceSet(int groupIndex, int consCounter) {
41: this .referencedGroup = groupIndex;
42: this .consCounter = consCounter;
43: }
44:
45: public int accepts(int strIndex, CharSequence testString) {
46: throw new PatternSyntaxException(
47: Messages.getString("regex.04"), "", //$NON-NLS-1$ //$NON-NLS-2$
48: 0);
49: }
50:
51: public int matches(int stringIndex, CharSequence testString,
52: MatchResultImpl matchResult) {
53: String group = getString(matchResult);
54:
55: if (group == null
56: || (stringIndex + group.length()) > matchResult
57: .getRightBound())
58: return -1;
59:
60: for (int i = 0; i < group.length(); i++) {
61: if (group.charAt(i) != testString.charAt(stringIndex + i)
62: && Pattern.getSupplement(group.charAt(i)) != testString
63: .charAt(stringIndex + i)) {
64: return -1;
65: }
66: }
67: matchResult.setConsumed(consCounter, group.length());
68: return next.matches(stringIndex + group.length(), testString,
69: matchResult);
70: }
71:
72: public AbstractSet getNext() {
73: return this .next;
74: }
75:
76: public void setNext(AbstractSet next) {
77: this .next = next;
78: }
79:
80: protected String getString(MatchResultImpl matchResult) {
81: String res = matchResult.getGroupNoCheck(referencedGroup);
82: return res;
83: // return (res != null) ? res : "";
84: }
85:
86: public String getName() {
87: return "CI back reference: " + this .groupIndex; //$NON-NLS-1$
88: }
89:
90: public boolean hasConsumed(MatchResultImpl matchResult) {
91: int cons;
92: boolean res = ((cons = matchResult.getConsumed(consCounter)) < 0 || cons > 0);
93: matchResult.setConsumed(consCounter, -1);
94: return res;
95: }
96:
97: }
|