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.Object
Encapsulates algorithm to recognize certain string pattern. When fed with a character range, aPattern
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
Fields Modifier and Type Field Description static int
MISMATCH
Returned 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 Pattern
atLeast(int min)
ReturnsPattern
object that matches this pattern for at leastmin
times.Pattern
atMost(int max)
ReturnsPattern
object that matches this pattern for up tomax
times.Pattern
ifelse(Pattern consequence, Pattern alternative)
ReturnsPattern
object that, if this pattern matches, matches the remaining input againstconsequence
pattern, or otherwise matches againstalternative
pattern.private static Pattern
ifElse(Pattern cond, Pattern consequence, Pattern alternative)
Pattern
many()
Returns aPattern
object that matches this pattern for 0 or more times.Pattern
many(int min)
Deprecated.UseatLeast(int)
instead.Pattern
many1()
Returns aPattern
object that matches this pattern for 1 or more times.abstract int
match(java.lang.CharSequence src, int begin, int end)
Matches character range against the pattern.Pattern
next(Pattern next)
Pattern
not()
Returns aPattern
object that only matches if this pattern mismatches, 0 is returned otherwise.Pattern
optional()
Returns aPattern
object that matches with 0 length even ifthis
mismatches.Pattern
or(Pattern p2)
Pattern
peek()
ReturnsPattern
object that matches with match length 0 if this Pattern object matches.Pattern
repeat(int n)
Deprecated.Usetimes(int)
instead.Pattern
some(int max)
Deprecated.UseatMost(int)
instead.Pattern
some(int min, int max)
Deprecated.Usetimes(int, int)
instead.Pattern
times(int n)
ReturnsPattern
object that matches the input against this pattern forn
times.Pattern
times(int min, int max)
private static Pattern
times(Pattern pp, int min, int max)
Parser<java.lang.Void>
toScanner(java.lang.String name)
Returns a scanner parser usingthis
pattern.
-
-
-
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 aPattern
object that sequentially matches the character range againstthis
and 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 aPattern
object that matches with 0 length even ifthis
mismatches.
-
many
public final Pattern many()
Returns aPattern
object 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.ReturnsPattern
object that matches this pattern for at leastmin
times. 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)
ReturnsPattern
object that matches this pattern for at leastmin
times. 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 aPattern
object 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.ReturnsPattern
object that matches this pattern for up tomax
times. 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)
ReturnsPattern
object that matches this pattern for up tomax
times. 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.ReturnsPattern
object that matches this pattern for at leastmin
times and up tomax
times. 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)
ReturnsPattern
object that matches this pattern for at leastmin
times and up tomax
times. 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 aPattern
object that only matches if this pattern mismatches, 0 is returned otherwise.
-
peek
public final Pattern peek()
ReturnsPattern
object that matches with match length 0 if this Pattern object matches.
-
ifelse
public final Pattern ifelse(Pattern consequence, Pattern alternative)
ReturnsPattern
object that, if this pattern matches, matches the remaining input againstconsequence
pattern, or otherwise matches againstalternative
pattern.
-
repeat
@Deprecated public final Pattern repeat(int n)
Deprecated.Usetimes(int)
instead.ReturnsPattern
object that matches the input against this pattern forn
times.
-
times
public final Pattern times(int n)
ReturnsPattern
object that matches the input against this pattern forn
times.- Since:
- 2.2
-
toScanner
public final Parser<java.lang.Void> toScanner(java.lang.String name)
Returns a scanner parser usingthis
pattern. Convenient short-hand forScanners.pattern(org.jparsec.pattern.Pattern, java.lang.String)
.- Since:
- 2.2
-
-