/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* A class to represent a pool of regular expressions. A string
* can be matched against the whole pool all at once. It is much
* faster than doing individual regular expression matches one-by-one.
*
* @see java.misc.RegexpTarget
* @author James Gosling
*/
public class RegexpPool {
public RegexpPool () {
}
/**
* Add a regular expression to the pool of regular expressions.
* @param re The regular expression to add to the pool.
For now, only handles strings that either begin or end with
a '*'.
* @param ret The object to be returned when this regular expression is
matched. If ret is an instance of the RegexpTarget class, ret.found
is called with the string fragment that matched the '*' as its
parameter.
* @exception REException error
*/
}
/**
* Replace the target for the regular expression with a different
* target.
*
* @param re The regular expression to be replaced in the pool.
* For now, only handles strings that either begin or end with
* a '*'.
* @param ret The object to be returned when this regular expression is
* matched. If ret is an instance of the RegexpTarget class, ret.found
* is called with the string fragment that matched the '*' as its
* parameter.
*/
try {
} catch(Exception e) {
// should never occur if replace is true
}
}
/**
* Delete the regular expression and its target.
* @param re The regular expression to be deleted from the pool.
* must begin or end with a '*'
* @return target - the old target.
*/
RegexpNode p = prefixMachine;
RegexpNode best = p;
int i;
boolean prefix = true;
len++;
if (len <= 0)
return null;
/* March forward through the prefix machine */
for (i = 0; p != null; i++) {
best = p;
}
if (i >= len)
break;
}
/* march backward through the suffix machine */
p = suffixMachine;
prefix = false;
best = p;
}
}
// delete only if there is an exact match
if (prefix) {
}
} else {
}
}
return o;
}
/** Search for a match to a string & return the object associated
with it with the match. When multiple regular expressions
would match the string, the best match is returned first.
The next best match is returned the next time matchNext is
called.
@param s The string to match against the regular expressions
in the pool.
@return null on failure, otherwise the object associated with
the regular expression when it was added to the pool.
If the object is an instance of RegexpTarget, then
the return value is the result from calling
return.found(string_that_matched_wildcard).
*/
return matchAfter(s, BIG);
}
/** Identical to match except that it will only find matches to
regular expressions that were added to the pool <i>after</i>
the last regular expression that matched in the last call
to match() or matchNext() */
return matchAfter(s, lastDepth);
}
RegexpNode p;
p = suffixMachine;
while (len > 1)
} else {
boolean exact = false;
len--;
else
exact = true;
p = prefixMachine;
for (int i = 0; i < len; i++)
}
}
RegexpNode p = prefixMachine;
RegexpNode best = p;
int bst = 0;
int bend = 0;
int i;
if (len <= 0)
return null;
/* March forward through the prefix machine */
for (i = 0; p != null; i++) {
best = p;
bst = i;
}
if (i >= len)
break;
}
/* march backward through the suffix machine */
p = suffixMachine;
best = p;
bst = 0;
bend = i+1;
}
}
if (o != null && o instanceof RegexpTarget)
return o;
}
/** Resets the pool so that the next call to matchNext looks
at all regular expressions in the pool. match(s); is equivalent
to reset(); matchNext(s);
regular expression pool. If multiple threads could be using this
pool this way, they should be syncronized to avoid race hazards.
match() was done in such a way that there are no such race
hazards: multiple threads can be matching in the same pool
simultaneously. */
public void reset() {
}
/** Print this pool to standard output */
}
}
}
}
/* A node in a regular expression finite state machine. */
class RegexpNode {
char c;
int depth;
boolean exact;
RegexpNode () {
c = '#';
depth = 0;
}
c = C;
}
RegexpNode p = firstchild;
if (p == null)
else {
while (p != null)
if (p.c == C)
return p;
else
p = p.nextsibling;
p.nextsibling = firstchild;
}
firstchild = p;
return p;
}
for (RegexpNode p = firstchild;
p != null;
p = p.nextsibling)
if (p.c == C)
return p;
return null;
}
if (nextsibling != null) {
RegexpNode p = this;
while (p != null) {
if (p.firstchild != null)
p = p.nextsibling;
}
} else {
if (firstchild != null)
}
}
}