corda/test/regex/TrivialMatcher.java
Johannes Schindelin 84829dc390 Refactor Pattern / Matcher classes
This makes both the Pattern and the Matcher class abstract so that more
specialized patterns than the trivial patterns we support so far can be
implemented as convenient subclasses of the respective abstract base
classes.

To ease development, we work on copies in test/regex/ in the 'regex'
package. That way, it can be developed in Eclipse (because it does not
interfere with Oracle JRE's java.util.regex.* classes).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2013-12-03 12:28:10 -06:00

49 lines
1.0 KiB
Java

/* Copyright (c) 2008-2013, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package regex;
/**
* This is a work in progress.
*
* @author zsombor and others
*/
class TrivialMatcher extends Matcher {
private final String pattern;
TrivialMatcher(String pattern, CharSequence input) {
super(input);
this.pattern = pattern;
}
public boolean matches() {
if (pattern.equals(input.toString())) {
start = 0;
end = input.length();
return true;
} else {
return false;
}
}
public boolean find(int start) {
String p = pattern;
int i = TrivialPattern.indexOf(input, p, start);
if (i >= 0) {
this.start = i;
this.end = i + p.length();
return true;
} else {
return false;
}
}
}