Method from org.apache.xerces.impl.xpath.regex.RegularExpression Detail: |
public boolean equals(Object obj) {
if (obj == null) return false;
if (!(obj instanceof RegularExpression))
return false;
RegularExpression r = (RegularExpression)obj;
return this.regex.equals(r.regex) && this.options == r.options;
}
Return true if patterns are the same and the options are equivalent. |
boolean equals(String pattern,
int options) {
return this.regex.equals(pattern) && this.options == options;
}
|
public int getNumberOfGroups() {
return this.nofparen;
}
Return the number of regular expression groups.
This method returns 1 when the regular expression has no capturing-parenthesis. |
public String getOptions() {
return REUtil.createOptionString(this.options);
}
Returns a option string.
The order of letters in it may be different from a string specified
in a constructor or setPattern() . |
public String getPattern() {
return this.regex;
}
|
public int hashCode() {
return (this.regex+"/"+this.getOptions()).hashCode();
}
|
public boolean matches(char[] target) {
return this.matches(target, 0, target .length , (Match)null);
}
Checks whether the target text contains this pattern or not. |
public boolean matches(String target) {
return this.matches(target, 0, target .length() , (Match)null);
}
Checks whether the target text contains this pattern or not. |
public boolean matches(CharacterIterator target) {
return this.matches(target, (Match)null);
}
Checks whether the target text contains this pattern or not. |
public boolean matches(char[] target,
Match match) {
return this.matches(target, 0, target .length , match);
}
Checks whether the target text contains this pattern or not. |
public boolean matches(String target,
Match match) {
return this.matches(target, 0, target .length() , match);
}
Checks whether the target text contains this pattern or not. |
public boolean matches(CharacterIterator target,
Match match) {
int start = target.getBeginIndex();
int end = target.getEndIndex();
synchronized (this) {
if (this.operations == null)
this.prepare();
if (this.context == null)
this.context = new Context();
}
Context con = null;
synchronized (this.context) {
con = this.context.inuse ? new Context() : this.context;
con.reset(target, start, end, this.numberOfClosures);
}
if (match != null) {
match.setNumberOfGroups(this.nofparen);
match.setSource(target);
} else if (this.hasBackReferences) {
match = new Match();
match.setNumberOfGroups(this.nofparen);
// Need not to call setSource() because
// a caller can not access this match instance.
}
con.match = match;
if (RegularExpression.isSet(this.options, XMLSCHEMA_MODE)) {
int matchEnd = this. matchCharacterIterator (con, this.operations, con.start, 1, this.options);
//System.err.println("DEBUG: matchEnd="+matchEnd);
if (matchEnd == con.limit) {
if (con.match != null) {
con.match.setBeginning(0, con.start);
con.match.setEnd(0, matchEnd);
}
con.inuse = false;
return true;
}
return false;
}
/*
* The pattern has only fixed string.
* The engine uses Boyer-Moore.
*/
if (this.fixedStringOnly) {
//System.err.println("DEBUG: fixed-only: "+this.fixedString);
int o = this.fixedStringTable.matches(target, con.start, con.limit);
if (o >= 0) {
if (con.match != null) {
con.match.setBeginning(0, o);
con.match.setEnd(0, o+this.fixedString.length());
}
con.inuse = false;
return true;
}
con.inuse = false;
return false;
}
/*
* The pattern contains a fixed string.
* The engine checks with Boyer-Moore whether the text contains the fixed string or not.
* If not, it return with false.
*/
if (this.fixedString != null) {
int o = this.fixedStringTable.matches(target, con.start, con.limit);
if (o < 0) {
//System.err.println("Non-match in fixed-string search.");
con.inuse = false;
return false;
}
}
int limit = con.limit-this.minlength;
int matchStart;
int matchEnd = -1;
/*
* Checks whether the expression starts with ".*".
*/
if (this.operations != null
&& this.operations.type == Op.CLOSURE && this.operations.getChild().type == Op.DOT) {
if (isSet(this.options, SINGLE_LINE)) {
matchStart = con.start;
matchEnd = this. matchCharacterIterator (con, this.operations, con.start, 1, this.options);
} else {
boolean previousIsEOL = true;
for (matchStart = con.start; matchStart < = limit; matchStart ++) {
int ch = target .setIndex( matchStart ) ;
if (isEOLChar(ch)) {
previousIsEOL = true;
} else {
if (previousIsEOL) {
if (0 < = (matchEnd = this. matchCharacterIterator (con, this.operations,
matchStart, 1, this.options)))
break;
}
previousIsEOL = false;
}
}
}
}
/*
* Optimization against the first character.
*/
else if (this.firstChar != null) {
//System.err.println("DEBUG: with firstchar-matching: "+this.firstChar);
RangeToken range = this.firstChar;
if (RegularExpression.isSet(this.options, IGNORE_CASE)) {
range = this.firstChar.getCaseInsensitiveToken();
for (matchStart = con.start; matchStart < = limit; matchStart ++) {
int ch = target .setIndex( matchStart ) ;
if (REUtil.isHighSurrogate(ch) && matchStart+1 < con.limit) {
ch = REUtil.composeFromSurrogates(ch, target .setIndex( matchStart+1 ) );
if (!range.match(ch)) continue;
} else {
if (!range.match(ch)) {
char ch1 = Character.toUpperCase((char)ch);
if (!range.match(ch1))
if (!range.match(Character.toLowerCase(ch1)))
continue;
}
}
if (0 < = (matchEnd = this. matchCharacterIterator (con, this.operations,
matchStart, 1, this.options)))
break;
}
} else {
for (matchStart = con.start; matchStart < = limit; matchStart ++) {
int ch = target .setIndex( matchStart ) ;
if (REUtil.isHighSurrogate(ch) && matchStart+1 < con.limit)
ch = REUtil.composeFromSurrogates(ch, target .setIndex( matchStart+1 ) );
if (!range.match(ch)) continue;
if (0 < = (matchEnd = this. matchCharacterIterator (con, this.operations,
matchStart, 1, this.options)))
break;
}
}
}
/*
* Straightforward matching.
*/
else {
for (matchStart = con.start; matchStart < = limit; matchStart ++) {
if (0 < = (matchEnd = this. matchCharacterIterator (con, this.operations, matchStart, 1, this.options)))
break;
}
}
if (matchEnd >= 0) {
if (con.match != null) {
con.match.setBeginning(0, matchStart);
con.match.setEnd(0, matchEnd);
}
con.inuse = false;
return true;
} else {
con.inuse = false;
return false;
}
}
Checks whether the target text contains this pattern or not. |
public boolean matches(char[] target,
int start,
int end) {
return this.matches(target, start, end, (Match)null);
}
Checks whether the target text contains this pattern
in specified range or not. |
public boolean matches(String target,
int start,
int end) {
return this.matches(target, start, end, (Match)null);
}
Checks whether the target text contains this pattern
in specified range or not. |
public boolean matches(char[] target,
int start,
int end,
Match match) {
synchronized (this) {
if (this.operations == null)
this.prepare();
if (this.context == null)
this.context = new Context();
}
Context con = null;
synchronized (this.context) {
con = this.context.inuse ? new Context() : this.context;
con.reset(target, start, end, this.numberOfClosures);
}
if (match != null) {
match.setNumberOfGroups(this.nofparen);
match.setSource(target);
} else if (this.hasBackReferences) {
match = new Match();
match.setNumberOfGroups(this.nofparen);
// Need not to call setSource() because
// a caller can not access this match instance.
}
con.match = match;
if (RegularExpression.isSet(this.options, XMLSCHEMA_MODE)) {
int matchEnd = this. matchCharArray (con, this.operations, con.start, 1, this.options);
//System.err.println("DEBUG: matchEnd="+matchEnd);
if (matchEnd == con.limit) {
if (con.match != null) {
con.match.setBeginning(0, con.start);
con.match.setEnd(0, matchEnd);
}
con.inuse = false;
return true;
}
return false;
}
/*
* The pattern has only fixed string.
* The engine uses Boyer-Moore.
*/
if (this.fixedStringOnly) {
//System.err.println("DEBUG: fixed-only: "+this.fixedString);
int o = this.fixedStringTable.matches(target, con.start, con.limit);
if (o >= 0) {
if (con.match != null) {
con.match.setBeginning(0, o);
con.match.setEnd(0, o+this.fixedString.length());
}
con.inuse = false;
return true;
}
con.inuse = false;
return false;
}
/*
* The pattern contains a fixed string.
* The engine checks with Boyer-Moore whether the text contains the fixed string or not.
* If not, it return with false.
*/
if (this.fixedString != null) {
int o = this.fixedStringTable.matches(target, con.start, con.limit);
if (o < 0) {
//System.err.println("Non-match in fixed-string search.");
con.inuse = false;
return false;
}
}
int limit = con.limit-this.minlength;
int matchStart;
int matchEnd = -1;
/*
* Checks whether the expression starts with ".*".
*/
if (this.operations != null
&& this.operations.type == Op.CLOSURE && this.operations.getChild().type == Op.DOT) {
if (isSet(this.options, SINGLE_LINE)) {
matchStart = con.start;
matchEnd = this. matchCharArray (con, this.operations, con.start, 1, this.options);
} else {
boolean previousIsEOL = true;
for (matchStart = con.start; matchStart < = limit; matchStart ++) {
int ch = target [ matchStart ] ;
if (isEOLChar(ch)) {
previousIsEOL = true;
} else {
if (previousIsEOL) {
if (0 < = (matchEnd = this. matchCharArray (con, this.operations,
matchStart, 1, this.options)))
break;
}
previousIsEOL = false;
}
}
}
}
/*
* Optimization against the first character.
*/
else if (this.firstChar != null) {
//System.err.println("DEBUG: with firstchar-matching: "+this.firstChar);
RangeToken range = this.firstChar;
if (RegularExpression.isSet(this.options, IGNORE_CASE)) {
range = this.firstChar.getCaseInsensitiveToken();
for (matchStart = con.start; matchStart < = limit; matchStart ++) {
int ch = target [ matchStart ] ;
if (REUtil.isHighSurrogate(ch) && matchStart+1 < con.limit) {
ch = REUtil.composeFromSurrogates(ch, target [ matchStart+1 ] );
if (!range.match(ch)) continue;
} else {
if (!range.match(ch)) {
char ch1 = Character.toUpperCase((char)ch);
if (!range.match(ch1))
if (!range.match(Character.toLowerCase(ch1)))
continue;
}
}
if (0 < = (matchEnd = this. matchCharArray (con, this.operations,
matchStart, 1, this.options)))
break;
}
} else {
for (matchStart = con.start; matchStart < = limit; matchStart ++) {
int ch = target [ matchStart ] ;
if (REUtil.isHighSurrogate(ch) && matchStart+1 < con.limit)
ch = REUtil.composeFromSurrogates(ch, target [ matchStart+1 ] );
if (!range.match(ch)) continue;
if (0 < = (matchEnd = this. matchCharArray (con, this.operations,
matchStart, 1, this.options)))
break;
}
}
}
/*
* Straightforward matching.
*/
else {
for (matchStart = con.start; matchStart < = limit; matchStart ++) {
if (0 < = (matchEnd = this. matchCharArray (con, this.operations, matchStart, 1, this.options)))
break;
}
}
if (matchEnd >= 0) {
if (con.match != null) {
con.match.setBeginning(0, matchStart);
con.match.setEnd(0, matchEnd);
}
con.inuse = false;
return true;
} else {
con.inuse = false;
return false;
}
}
Checks whether the target text contains this pattern
in specified range or not. |
public boolean matches(String target,
int start,
int end,
Match match) {
synchronized (this) {
if (this.operations == null)
this.prepare();
if (this.context == null)
this.context = new Context();
}
Context con = null;
synchronized (this.context) {
con = this.context.inuse ? new Context() : this.context;
con.reset(target, start, end, this.numberOfClosures);
}
if (match != null) {
match.setNumberOfGroups(this.nofparen);
match.setSource(target);
} else if (this.hasBackReferences) {
match = new Match();
match.setNumberOfGroups(this.nofparen);
// Need not to call setSource() because
// a caller can not access this match instance.
}
con.match = match;
if (RegularExpression.isSet(this.options, XMLSCHEMA_MODE)) {
if (DEBUG) {
System.err.println("target string="+target);
}
int matchEnd = this. matchString (con, this.operations, con.start, 1, this.options);
if (DEBUG) {
System.err.println("matchEnd="+matchEnd);
System.err.println("con.limit="+con.limit);
}
if (matchEnd == con.limit) {
if (con.match != null) {
con.match.setBeginning(0, con.start);
con.match.setEnd(0, matchEnd);
}
con.inuse = false;
return true;
}
return false;
}
/*
* The pattern has only fixed string.
* The engine uses Boyer-Moore.
*/
if (this.fixedStringOnly) {
//System.err.println("DEBUG: fixed-only: "+this.fixedString);
int o = this.fixedStringTable.matches(target, con.start, con.limit);
if (o >= 0) {
if (con.match != null) {
con.match.setBeginning(0, o);
con.match.setEnd(0, o+this.fixedString.length());
}
con.inuse = false;
return true;
}
con.inuse = false;
return false;
}
/*
* The pattern contains a fixed string.
* The engine checks with Boyer-Moore whether the text contains the fixed string or not.
* If not, it return with false.
*/
if (this.fixedString != null) {
int o = this.fixedStringTable.matches(target, con.start, con.limit);
if (o < 0) {
//System.err.println("Non-match in fixed-string search.");
con.inuse = false;
return false;
}
}
int limit = con.limit-this.minlength;
int matchStart;
int matchEnd = -1;
/*
* Checks whether the expression starts with ".*".
*/
if (this.operations != null
&& this.operations.type == Op.CLOSURE && this.operations.getChild().type == Op.DOT) {
if (isSet(this.options, SINGLE_LINE)) {
matchStart = con.start;
matchEnd = this. matchString (con, this.operations, con.start, 1, this.options);
} else {
boolean previousIsEOL = true;
for (matchStart = con.start; matchStart < = limit; matchStart ++) {
int ch = target .charAt( matchStart ) ;
if (isEOLChar(ch)) {
previousIsEOL = true;
} else {
if (previousIsEOL) {
if (0 < = (matchEnd = this. matchString (con, this.operations,
matchStart, 1, this.options)))
break;
}
previousIsEOL = false;
}
}
}
}
/*
* Optimization against the first character.
*/
else if (this.firstChar != null) {
//System.err.println("DEBUG: with firstchar-matching: "+this.firstChar);
RangeToken range = this.firstChar;
if (RegularExpression.isSet(this.options, IGNORE_CASE)) {
range = this.firstChar.getCaseInsensitiveToken();
for (matchStart = con.start; matchStart < = limit; matchStart ++) {
int ch = target .charAt( matchStart ) ;
if (REUtil.isHighSurrogate(ch) && matchStart+1 < con.limit) {
ch = REUtil.composeFromSurrogates(ch, target .charAt( matchStart+1 ) );
if (!range.match(ch)) continue;
} else {
if (!range.match(ch)) {
char ch1 = Character.toUpperCase((char)ch);
if (!range.match(ch1))
if (!range.match(Character.toLowerCase(ch1)))
continue;
}
}
if (0 < = (matchEnd = this. matchString (con, this.operations,
matchStart, 1, this.options)))
break;
}
} else {
for (matchStart = con.start; matchStart < = limit; matchStart ++) {
int ch = target .charAt( matchStart ) ;
if (REUtil.isHighSurrogate(ch) && matchStart+1 < con.limit)
ch = REUtil.composeFromSurrogates(ch, target .charAt( matchStart+1 ) );
if (!range.match(ch)) continue;
if (0 < = (matchEnd = this. matchString (con, this.operations,
matchStart, 1, this.options)))
break;
}
}
}
/*
* Straightforward matching.
*/
else {
for (matchStart = con.start; matchStart < = limit; matchStart ++) {
if (0 < = (matchEnd = this. matchString (con, this.operations, matchStart, 1, this.options)))
break;
}
}
if (matchEnd >= 0) {
if (con.match != null) {
con.match.setBeginning(0, matchStart);
con.match.setEnd(0, matchEnd);
}
con.inuse = false;
return true;
} else {
con.inuse = false;
return false;
}
}
Checks whether the target text contains this pattern
in specified range or not. |
void prepare() {
if (Op.COUNT) Op.nofinstances = 0;
this.compile(this.tokentree);
/*
if (this.operations.type == Op.CLOSURE && this.operations.getChild().type == Op.DOT) { // .*
Op anchor = Op.createAnchor(isSet(this.options, SINGLE_LINE) ? 'A' : '@');
anchor.next = this.operations;
this.operations = anchor;
}
*/
if (Op.COUNT) System.err.println("DEBUG: The number of operations: "+Op.nofinstances);
this.minlength = this.tokentree.getMinLength();
this.firstChar = null;
if (!isSet(this.options, PROHIBIT_HEAD_CHARACTER_OPTIMIZATION)
&& !isSet(this.options, XMLSCHEMA_MODE)) {
RangeToken firstChar = Token.createRange();
int fresult = this.tokentree.analyzeFirstCharacter(firstChar, this.options);
if (fresult == Token.FC_TERMINAL) {
firstChar.compactRanges();
this.firstChar = firstChar;
if (DEBUG)
System.err.println("DEBUG: Use the first character optimization: "+firstChar);
}
}
if (this.operations != null
&& (this.operations.type == Op.STRING || this.operations.type == Op.CHAR)
&& this.operations.next == null) {
if (DEBUG)
System.err.print(" *** Only fixed string! *** ");
this.fixedStringOnly = true;
if (this.operations.type == Op.STRING)
this.fixedString = this.operations.getString();
else if (this.operations.getData() >= 0x10000) { // Op.CHAR
this.fixedString = REUtil.decomposeToSurrogates(this.operations.getData());
} else {
char[] ac = new char[1];
ac[0] = (char)this.operations.getData();
this.fixedString = new String(ac);
}
this.fixedStringOptions = this.options;
this.fixedStringTable = new BMPattern(this.fixedString, 256,
isSet(this.fixedStringOptions, IGNORE_CASE));
} else if (!isSet(this.options, PROHIBIT_FIXED_STRING_OPTIMIZATION)
&& !isSet(this.options, XMLSCHEMA_MODE)) {
Token.FixedStringContainer container = new Token.FixedStringContainer();
this.tokentree.findFixedString(container, this.options);
this.fixedString = container.token == null ? null : container.token.getString();
this.fixedStringOptions = container.options;
if (this.fixedString != null && this.fixedString.length() < 2)
this.fixedString = null;
// This pattern has a fixed string of which length is more than one.
if (this.fixedString != null) {
this.fixedStringTable = new BMPattern(this.fixedString, 256,
isSet(this.fixedStringOptions, IGNORE_CASE));
if (DEBUG) {
System.err.println("DEBUG: The longest fixed string: "+this.fixedString.length()
+"/" //+this.fixedString
+"/"+REUtil.createOptionString(this.fixedStringOptions));
System.err.print("String: ");
REUtil.dumpString(this.fixedString);
}
}
}
}
Prepares for matching. This method is called just before starting matching. |
public void setPattern(String newPattern) throws ParseException {
this.setPattern(newPattern, this.options);
}
|
public void setPattern(String newPattern,
String options) throws ParseException {
this.setPattern(newPattern, REUtil.parseOptions(options));
}
|
public String toString() {
return this.tokentree.toString(this.options);
}
Represents this instence in String. |