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 int
Returned bymatch(CharSequence, int, int)
method when match fails. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal Pattern
atLeast
(int min) ReturnsPattern
object that matches this pattern for at leastmin
times.final Pattern
atMost
(int max) ReturnsPattern
object that matches this pattern for up tomax
times.final Pattern
ReturnsPattern
object that, if this pattern matches, matches the remaining input againstconsequence
pattern, or otherwise matches againstalternative
pattern.private static Pattern
final Pattern
many()
Returns aPattern
object that matches this pattern for 0 or more times.final Pattern
many
(int min) Deprecated.final Pattern
many1()
Returns aPattern
object that matches this pattern for 1 or more times.abstract int
match
(CharSequence src, int begin, int end) Matches character range against the pattern.final Pattern
final Pattern
not()
Returns aPattern
object that only matches if this pattern mismatches, 0 is returned otherwise.final Pattern
optional()
Returns aPattern
object that matches with 0 length even ifthis
mismatches.final Pattern
final Pattern
peek()
ReturnsPattern
object that matches with match length 0 if this Pattern object matches.final Pattern
repeat
(int n) Deprecated.Usetimes(int)
instead.final Pattern
some
(int max) Deprecated.UseatMost(int)
instead.final Pattern
some
(int min, int max) Deprecated.Usetimes(int, int)
instead.final Pattern
times
(int n) ReturnsPattern
object that matches the input against this pattern forn
times.final Pattern
times
(int min, int max) private static Pattern
Returns a scanner parser usingthis
pattern.
-
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 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
Returns aPattern
object that matches with 0 length even ifthis
mismatches. -
many
Returns aPattern
object that matches this pattern for 0 or more times. The total match length is returned. -
many
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
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
Returns aPattern
object that matches this pattern for 1 or more times. The total match length is returned. -
some
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
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.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
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
Returns aPattern
object that only matches if this pattern mismatches, 0 is returned otherwise. -
peek
ReturnsPattern
object that matches with match length 0 if this Pattern object matches. -
ifelse
ReturnsPattern
object that, if this pattern matches, matches the remaining input againstconsequence
pattern, or otherwise matches againstalternative
pattern. -
repeat
Deprecated.Usetimes(int)
instead.ReturnsPattern
object that matches the input against this pattern forn
times. -
times
ReturnsPattern
object that matches the input against this pattern forn
times.- Since:
- 2.2
-
or
-
toScanner
Returns a scanner parser usingthis
pattern. Convenient short-hand forScanners.pattern(org.jparsec.pattern.Pattern, java.lang.String)
.- Since:
- 2.2
-
ifElse
-
times
-
atLeast(int)
instead.