Package org.jparsec.pattern
Class Pattern
java.lang.Object
org.jparsec.pattern.Pattern
- Direct Known Subclasses:
LowerBoundedPattern,ManyPattern,NotPattern,OptionalPattern,OrPattern,PeekPattern,RepeatCharPredicatePattern,RepeatPattern,SequencePattern,UpperBoundedPattern
Encapsulates algorithm to recognize certain string pattern. When fed with a character range,
a
Pattern object either fails to match, or matches with the match length returned.
There is no error reported on where and what exactly failed.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intReturned bymatch(CharSequence, int, int)method when match fails. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal PatternatLeast(int min) ReturnsPatternobject that matches this pattern for at leastmintimes.final PatternatMost(int max) ReturnsPatternobject that matches this pattern for up tomaxtimes.final PatternReturnsPatternobject that, if this pattern matches, matches the remaining input againstconsequencepattern, or otherwise matches againstalternativepattern.private static Patternfinal Patternmany()Returns aPatternobject that matches this pattern for 0 or more times.final Patternmany(int min) Deprecated.final Patternmany1()Returns aPatternobject that matches this pattern for 1 or more times.abstract intmatch(CharSequence src, int begin, int end) Matches character range against the pattern.final Patternfinal Patternnot()Returns aPatternobject that only matches if this pattern mismatches, 0 is returned otherwise.final Patternoptional()Returns aPatternobject that matches with 0 length even ifthismismatches.final Patternfinal Patternpeek()ReturnsPatternobject that matches with match length 0 if this Pattern object matches.final Patternrepeat(int n) Deprecated.Usetimes(int)instead.final Patternsome(int max) Deprecated.UseatMost(int)instead.final Patternsome(int min, int max) Deprecated.Usetimes(int, int)instead.final Patterntimes(int n) ReturnsPatternobject that matches the input against this pattern forntimes.final Patterntimes(int min, int max) private static PatternReturns a scanner parser usingthispattern.
-
Field Details
-
MISMATCH
public static final int MISMATCHReturned bymatch(CharSequence, int, int)method when match fails.- See Also:
-
-
Constructor Details
-
Pattern
public Pattern()
-
-
Method Details
-
match
Matches character range against the pattern. The length of the range isend - begin.- Parameters:
src- the source string.begin- the beginning index in the sequence.end- the end index of the source string (exclusive). NOTE: the range is[begin, end).- Returns:
- the number of characters matched. MISMATCH otherwise.
-
next
Returns aPatternobject that sequentially matches the character range againstthisand thennext. If both succeeds, the entire match length is returned.- Parameters:
next- the next pattern to match.- Returns:
- the new Pattern object.
-
optional
Returns aPatternobject that matches with 0 length even ifthismismatches. -
many
Returns aPatternobject that matches this pattern for 0 or more times. The total match length is returned. -
many
Deprecated.UseatLeast(int)instead.ReturnsPatternobject that matches this pattern for at leastmintimes. The total match length is returned.- Parameters:
min- the minimal number of times to match.- Returns:
- the new Pattern object.
-
atLeast
ReturnsPatternobject that matches this pattern for at leastmintimes. The total match length is returned.- Parameters:
min- the minimal number of times to match.- Returns:
- the new Pattern object.
- Since:
- 2.2
-
many1
Returns aPatternobject that matches this pattern for 1 or more times. The total match length is returned. -
some
Deprecated.UseatMost(int)instead.ReturnsPatternobject that matches this pattern for up tomaxtimes. The total match length is returned.- Parameters:
max- the maximal number of times to match.- Returns:
- the new Pattern object.
-
atMost
ReturnsPatternobject that matches this pattern for up tomaxtimes. The total match length is returned.- Parameters:
max- the maximal number of times to match.- Returns:
- the new Pattern object.
- Since:
- 2.2
-
some
Deprecated.Usetimes(int, int)instead.ReturnsPatternobject that matches this pattern for at leastmintimes and up tomaxtimes. The total match length is returned.- Parameters:
min- the minimal number of times to match.max- the maximal number of times to match.- Returns:
- the new Pattern object.
-
times
ReturnsPatternobject that matches this pattern for at leastmintimes and up tomaxtimes. The total match length is returned.- Parameters:
min- the minimal number of times to match.max- the maximal number of times to match.- Returns:
- the new Pattern object.
- Since:
- 2.2
-
not
Returns aPatternobject that only matches if this pattern mismatches, 0 is returned otherwise. -
peek
ReturnsPatternobject that matches with match length 0 if this Pattern object matches. -
ifelse
ReturnsPatternobject that, if this pattern matches, matches the remaining input againstconsequencepattern, or otherwise matches againstalternativepattern. -
repeat
Deprecated.Usetimes(int)instead.ReturnsPatternobject that matches the input against this pattern forntimes. -
times
ReturnsPatternobject that matches the input against this pattern forntimes.- Since:
- 2.2
-
or
-
toScanner
Returns a scanner parser usingthispattern. Convenient short-hand forScanners.pattern(org.jparsec.pattern.Pattern, java.lang.String).- Since:
- 2.2
-
ifElse
-
times
-
atLeast(int)instead.