public final class Matchers extends Object
| Modifier and Type | Method and Description |
|---|---|
static Matcher<MultiResult> |
allOf(Matcher<?>... matchers)
Creates a matcher that matches if the examined input matches all of the specified
matchers.
|
static Matcher<MultiResult> |
anyOf(Matcher<?>... matchers)
Creates a matcher that matches if the examined input matches any of the specified
matchers.
|
static Matcher<Result> |
anyString()
Creates a matcher that matches when at least one character exists in the input buffer.
|
static Matcher<Result> |
contains(String string)
Creates a matcher of
String that matches when examined input contains the given
substring. |
static Matcher<Result> |
eof()
Creates a matcher that matches if input reaches the end of stream.
|
static Matcher<Result> |
exact(String exact)
Creates a matcher that matches when the given string is equal to the
input buffer contents.
|
static Matcher<Result> |
matches(Pattern pattern)
Creates a matcher of
Pattern that matches when examined input fully matches
the given regular
expression. |
static Matcher<Result> |
matches(String pattern)
Creates a matcher of
String that matches when examined input fully matches
the given regular
expression. |
static Matcher<Result> |
regexp(Pattern pattern)
Creates a matcher of
Pattern that matches when examined input contains the
given regular
expression. |
static Matcher<Result> |
regexp(String pattern)
Creates a matcher of
String that matches when examined input contains the
given regular
expression. |
static Matcher<MultiResult> |
sequence(Matcher<?>... matchers)
Matches the given matchers one by one.
|
static Matcher<Result> |
startsWith(String prefix)
Creates a matcher that matches when the input buffer starts with the given string.
|
static Matcher<MultiResult> |
times(int number,
Matcher<?> matcher)
Creates a matcher that matches if the given
matcher matches the number of
times. |
public static Matcher<Result> matches(String pattern)
String that matches when examined input fully matches
the given regular
expression.
This method simply compiles the given pattern to a Pattern and
passes it to the
matches(java.util.regex.Pattern) method.pattern - the pattern that represents regular expressionregexp(java.util.regex.Pattern)public static Matcher<Result> matches(Pattern pattern)
Pattern that matches when examined input fully matches
the given regular
expression. The operation is equivalent to the Matcher.matches()
method.
The returning Result implements the MatchResult methods to
query the results
of the regular expression match.
If the match succeeded, the input buffer is cleared and .Result#getBefore() returns
an empty string.pattern - the representation of a regular expressionpublic static Matcher<Result> regexp(String pattern)
String that matches when examined input contains the
given regular
expression.
This method simply compiles the given string to a Pattern and
passes it to the
regexp(java.util.regex.Pattern) method.pattern - the string that represents regular expressionregexp(java.util.regex.Pattern)public static Matcher<Result> regexp(Pattern pattern)
Pattern that matches when examined input contains the
given regular
expression. The operation is equivalent to the Matcher.find() method.
The returning Result implements the MatchResult methods to
query the results
of the regular expression match.
If the match succeeded, the input buffer is updated: the input part from the beginning
until the end
position of the match is removed.pattern - the representation of a regular expressionpublic static Matcher<Result> contains(String string)
String that matches when examined input contains the given
substring.
The returning Result has no groups except the one with 0 index which
represents the exact
string match.
If the match succeeded, the input buffer is updated: the input part from the beginning
until the end
position of the match is removed.string - the string to search forpublic static Matcher<MultiResult> allOf(Matcher<?>... matchers)
Result instance returned
by this method.
If the result is negative, then the one which fails first is returned.
If several matchers the have same end position, then the result from the one with the
smaller argument index is
returned.matchers - the vararg array of the matcherspublic static Matcher<MultiResult> anyOf(Matcher<?>... matchers)
Result instance returned
by this method.
If several matchers have the same end position, then the result from the one with the
smaller argument index is
returned.matchers - the vararg array of the matcherspublic static Matcher<Result> eof()
Result.getBefore() will return the entire input
buffer, and
the MatchResult.group() returns an empty string.public static Matcher<MultiResult> times(int number, Matcher<?> matcher)
matcher matches the number of
times.
The match result represents a combination of all the performed match operations. If
succeeded, the result
with the greatest end position is returned.
number - the number of times which the given matcher must match the inputmatcher - the matcherpublic static Matcher<MultiResult> sequence(Matcher<?>... matchers)
matchers - the collection of matchers.public static Matcher<Result> anyString()
Result.getBefore() returns an
empty string, the
MatchResult.group() returns the entire input buffer.public static Matcher<Result> exact(String exact)
Result.getBefore() returns an
empty string, the MatchResult.group() returns the entire input buffer.exact - the string to match.public static Matcher<Result> startsWith(String prefix)
Result.getBefore() returns an
empty string, the MatchResult.group() returns the given string.prefix - the prefix string to match.Copyright © 2014–2018 Alexey Gavrilov and contributors. All rights reserved.