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
public abstract class Pattern extends java.lang.ObjectEncapsulates algorithm to recognize certain string pattern. When fed with a character range, aPatternobject either fails to match, or matches with the match length returned. There is no error reported on where and what exactly failed.
-
-
Field Summary
Fields Modifier and Type Field Description static intMISMATCHReturned bymatch(CharSequence, int, int)method when match fails.
-
Constructor Summary
Constructors Constructor Description Pattern()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description PatternatLeast(int min)ReturnsPatternobject that matches this pattern for at leastmintimes.PatternatMost(int max)ReturnsPatternobject that matches this pattern for up tomaxtimes.Patternifelse(Pattern consequence, Pattern alternative)ReturnsPatternobject that, if this pattern matches, matches the remaining input againstconsequencepattern, or otherwise matches againstalternativepattern.private static PatternifElse(Pattern cond, Pattern consequence, Pattern alternative)Patternmany()Returns aPatternobject that matches this pattern for 0 or more times.Patternmany(int min)Deprecated.UseatLeast(int)instead.Patternmany1()Returns aPatternobject that matches this pattern for 1 or more times.abstract intmatch(java.lang.CharSequence src, int begin, int end)Matches character range against the pattern.Patternnext(Pattern next)Patternnot()Returns aPatternobject that only matches if this pattern mismatches, 0 is returned otherwise.Patternoptional()Returns aPatternobject that matches with 0 length even ifthismismatches.Patternor(Pattern p2)Patternpeek()ReturnsPatternobject that matches with match length 0 if this Pattern object matches.Patternrepeat(int n)Deprecated.Usetimes(int)instead.Patternsome(int max)Deprecated.UseatMost(int)instead.Patternsome(int min, int max)Deprecated.Usetimes(int, int)instead.Patterntimes(int n)ReturnsPatternobject that matches the input against this pattern forntimes.Patterntimes(int min, int max)private static Patterntimes(Pattern pp, int min, int max)Parser<java.lang.Void>toScanner(java.lang.String name)Returns a scanner parser usingthispattern.
-
-
-
Field Detail
-
MISMATCH
public static final int MISMATCH
Returned bymatch(CharSequence, int, int)method when match fails.- See Also:
- Constant Field Values
-
-
Method Detail
-
match
public abstract int match(java.lang.CharSequence src, int begin, int end)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
public final Pattern next(Pattern 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
public final Pattern optional()
Returns aPatternobject that matches with 0 length even ifthismismatches.
-
many
public final Pattern many()
Returns aPatternobject that matches this pattern for 0 or more times. The total match length is returned.
-
many
@Deprecated public final Pattern many(int min)
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
public final Pattern atLeast(int min)
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
public final Pattern many1()
Returns aPatternobject that matches this pattern for 1 or more times. The total match length is returned.
-
some
@Deprecated public final Pattern some(int max)
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
public final Pattern atMost(int max)
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 public final Pattern some(int min, int max)
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
public final Pattern times(int min, int max)
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
public final Pattern not()
Returns aPatternobject that only matches if this pattern mismatches, 0 is returned otherwise.
-
peek
public final Pattern peek()
ReturnsPatternobject that matches with match length 0 if this Pattern object matches.
-
ifelse
public final Pattern ifelse(Pattern consequence, Pattern alternative)
ReturnsPatternobject that, if this pattern matches, matches the remaining input againstconsequencepattern, or otherwise matches againstalternativepattern.
-
repeat
@Deprecated public final Pattern repeat(int n)
Deprecated.Usetimes(int)instead.ReturnsPatternobject that matches the input against this pattern forntimes.
-
times
public final Pattern times(int n)
ReturnsPatternobject that matches the input against this pattern forntimes.- Since:
- 2.2
-
toScanner
public final Parser<java.lang.Void> toScanner(java.lang.String name)
Returns a scanner parser usingthispattern. Convenient short-hand forScanners.pattern(org.jparsec.pattern.Pattern, java.lang.String).- Since:
- 2.2
-
-