001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Nikolay A. Kuznetsov
020: * @version $Revision: 1.4.2.2 $
021: */package java.util.regex;
022:
023: /**
024: * Valid constant zero character match.
025: *
026: * @author Nikolay A. Kuznetsov
027: * @version $Revision: 1.4.2.2 $
028: */
029: class EmptySet extends LeafSet {
030:
031: public EmptySet(AbstractSet next) {
032: super (next);
033: charCount = 0;
034: }
035:
036: /*
037: * @see java.util.regex.LeafSet#accepts(int, java.lang.CharSequence)
038: */
039: public int accepts(int stringIndex, CharSequence testString) {
040: return 0;
041: }
042:
043: public int find(int stringIndex, CharSequence testString,
044: MatchResultImpl matchResult) {
045: int strLength = matchResult.getRightBound();
046: int startStr = matchResult.getLeftBound();
047:
048: while (stringIndex <= strLength) {
049:
050: //check for supplementary codepoints
051: if (stringIndex < strLength) {
052: char low = testString.charAt(stringIndex);
053:
054: if (Character.isLowSurrogate(low)) {
055:
056: if (stringIndex > startStr) {
057: char high = testString.charAt(stringIndex - 1);
058: if (Character.isHighSurrogate(high)) {
059: stringIndex++;
060: continue;
061: }
062: }
063: }
064: }
065:
066: if (next.matches(stringIndex, testString, matchResult) >= 0) {
067: return stringIndex;
068: }
069: stringIndex++;
070: }
071:
072: return -1;
073: }
074:
075: public int findBack(int stringIndex, int startSearch,
076: CharSequence testString, MatchResultImpl matchResult) {
077: int strLength = matchResult.getRightBound();
078: int startStr = matchResult.getLeftBound();
079:
080: while (startSearch >= stringIndex) {
081:
082: //check for supplementary codepoints
083: if (startSearch < strLength) {
084: char low = testString.charAt(startSearch);
085:
086: if (Character.isLowSurrogate(low)) {
087:
088: if (startSearch > startStr) {
089: char high = testString.charAt(startSearch - 1);
090: if (Character.isHighSurrogate(high)) {
091: startSearch--;
092: continue;
093: }
094: }
095: }
096: }
097:
098: if (next.matches(startSearch, testString, matchResult) >= 0) {
099: return startSearch;
100: }
101: startSearch--;
102: }
103:
104: return -1;
105: }
106:
107: /*
108: * @see java.util.regex.AbstractSet#getName()
109: */
110: protected String getName() {
111: return "<Empty set>"; //$NON-NLS-1$
112: }
113:
114: public boolean hasConsumed(MatchResultImpl mr) {
115: return false;
116: }
117:
118: }
|