Top Description Fields Constructors Methods
org.jparsec.pattern

public abstract Class Pattern

extends Object
Class Inheritance
Known Direct Subclasses
org.jparsec.pattern.PeekPattern, org.jparsec.pattern.RepeatCharPredicatePattern, org.jparsec.pattern.RepeatPattern, org.jparsec.pattern.SequencePattern, org.jparsec.pattern.UpperBoundedPattern, org.jparsec.pattern.LowerBoundedPattern, org.jparsec.pattern.ManyPattern, org.jparsec.pattern.NotPattern, org.jparsec.pattern.OptionalPattern, org.jparsec.pattern.OrPattern
Imports
org.jparsec.Parser, .Scanners, org.jparsec.internal.util.Checks

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.
Author
Ben Yu

Field Summary

Modifier and TypeField and Description
public static final int
MISMATCH

Returned by match(CharSequence, int, int) method when match fails.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final Pattern

Returns:

the new Pattern object.
atLeast
(int
the minimal number of times to match.
min
)

Returns Pattern object that matches this pattern for at least min times.

public final Pattern

Returns:

the new Pattern object.
atMost
(int
the maximal number of times to match.
max
)

Returns Pattern object that matches this pattern for up to max times.

public final Pattern
ifelse(Pattern consequence, Pattern alternative)

Returns Pattern object that, if this pattern matches, matches the remaining input against consequence pattern, or otherwise matches against alternative pattern.

private static Pattern
ifElse(final Pattern cond, final Pattern consequence, final Pattern alternative)

public final Pattern
many()

Returns a Pattern object that matches this pattern for 0 or more times.

public final Pattern

Returns:

the new Pattern object.
many
(int
the minimal number of times to match.
min
)
Deprecated Use atLeast instead.

Returns Pattern object that matches this pattern for at least min times.

public final Pattern
many1()

Returns a Pattern object that matches this pattern for 1 or more times.

public abstract int

Returns:

the number of characters matched. MISMATCH otherwise.
match
(CharSequence
the source string.
src
,
int
the beginning index in the sequence.
begin
,
int
the end index of the source string (exclusive).

Note

the range is [begin, end).

end
)

Matches character range against the pattern.

public final Pattern

Returns:

the new Pattern object.
next
(Pattern
the next pattern to match.
next
)

Returns a Pattern object that sequentially matches the character range against this and then next.

public final Pattern
not()

Returns a Pattern object that only matches if this pattern mismatches, 0 is returned otherwise.

public final Pattern
optional()

Returns a Pattern object that matches with 0 length even if this mismatches.

public final Pattern
or(Pattern p2)

Returns Pattern object that matches if either this or p2 matches.

public final Pattern
peek()

Returns Pattern object that matches with match length 0 if this Pattern object matches.

public final Pattern
repeat(int n)
Deprecated Use times(int) instead.

Returns Pattern object that matches the input against this pattern for n times.

public final Pattern

Returns:

the new Pattern object.
some
(int
the maximal number of times to match.
max
)
Deprecated Use atMost instead.

Returns Pattern object that matches this pattern for up to max times.

public final Pattern

Returns:

the new Pattern object.
some
(int
the minimal number of times to match.
min
,
int
the maximal number of times to match.
max
)
Deprecated Use times(int, int) instead.

Returns Pattern object that matches this pattern for at least min times and up to max times.

public final Pattern

Returns:

the new Pattern object.
times
(int
the minimal number of times to match.
min
,
int
the maximal number of times to match.
max
)

Returns Pattern object that matches this pattern for at least min times and up to max times.

public final Pattern
times(int n)

Returns Pattern object that matches the input against this pattern for n times.

private static Pattern
times(final Pattern pp, final int min, final int max)

public final Parser<Void>
toScanner(String name)

Returns a scanner parser using this pattern.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

MISMATCHback to summary
public static final int MISMATCH

Returned by match(CharSequence, int, int) method when match fails.

Constructor Detail

Patternback to summary
public Pattern()

Method Detail

atLeastback to summary
public final Pattern atLeast(int min)

Returns Pattern object that matches this pattern for at least min times. The total match length is returned.

Parameters
min:int

the minimal number of times to match.

Returns:Pattern

the new Pattern object.

Since
2.2
atMostback to summary
public final Pattern atMost(int max)

Returns Pattern object that matches this pattern for up to max times. The total match length is returned.

Parameters
max:int

the maximal number of times to match.

Returns:Pattern

the new Pattern object.

Since
2.2
ifelseback to summary
public final Pattern ifelse(Pattern consequence, Pattern alternative)

Returns Pattern object that, if this pattern matches, matches the remaining input against consequence pattern, or otherwise matches against alternative pattern.

ifElseback to summary
private static Pattern ifElse(final Pattern cond, final Pattern consequence, final Pattern alternative)
manyback to summary
public final Pattern many()

Returns a Pattern object that matches this pattern for 0 or more times. The total match length is returned.

manyback to summary
public final Pattern many(int min)

Deprecated

Use atLeast instead.

Returns Pattern object that matches this pattern for at least min times. The total match length is returned.

Parameters
min:int

the minimal number of times to match.

Returns:Pattern

the new Pattern object.

Annotations
@Deprecated
many1back to summary
public final Pattern many1()

Returns a Pattern object that matches this pattern for 1 or more times. The total match length is returned.

matchback to summary
public abstract int match(CharSequence src, int begin, int end)

Matches character range against the pattern. The length of the range is end - begin.

Parameters
src:CharSequence

the source string.

begin:int

the beginning index in the sequence.

end:int

the end index of the source string (exclusive).

Note

the range is [begin, end).

Returns:int

the number of characters matched. MISMATCH otherwise.

nextback to summary
public final Pattern next(Pattern next)

Returns a Pattern object that sequentially matches the character range against this and then next. If both succeeds, the entire match length is returned.

Parameters
next:Pattern

the next pattern to match.

Returns:Pattern

the new Pattern object.

notback to summary
public final Pattern not()

Returns a Pattern object that only matches if this pattern mismatches, 0 is returned otherwise.

optionalback to summary
public final Pattern optional()

Returns a Pattern object that matches with 0 length even if this mismatches.

orback to summary
public final Pattern or(Pattern p2)

Returns Pattern object that matches if either this or p2 matches.

peekback to summary
public final Pattern peek()

Returns Pattern object that matches with match length 0 if this Pattern object matches.

repeatback to summary
public final Pattern repeat(int n)

Deprecated

Use times(int) instead.

Returns Pattern object that matches the input against this pattern for n times.

Annotations
@Deprecated
someback to summary
public final Pattern some(int max)

Deprecated

Use atMost instead.

Returns Pattern object that matches this pattern for up to max times. The total match length is returned.

Parameters
max:int

the maximal number of times to match.

Returns:Pattern

the new Pattern object.

Annotations
@Deprecated
someback to summary
public final Pattern some(int min, int max)

Deprecated

Use times(int, int) instead.

Returns Pattern object that matches this pattern for at least min times and up to max times. The total match length is returned.

Parameters
min:int

the minimal number of times to match.

max:int

the maximal number of times to match.

Returns:Pattern

the new Pattern object.

Annotations
@Deprecated
timesback to summary
public final Pattern times(int min, int max)

Returns Pattern object that matches this pattern for at least min times and up to max times. The total match length is returned.

Parameters
min:int

the minimal number of times to match.

max:int

the maximal number of times to match.

Returns:Pattern

the new Pattern object.

Since
2.2
timesback to summary
public final Pattern times(int n)

Returns Pattern object that matches the input against this pattern for n times.

Since
2.2
timesback to summary
private static Pattern times(final Pattern pp, final int min, final int max)
toScannerback to summary
public final Parser<Void> toScanner(String name)

Returns a scanner parser using this pattern. Convenient short-hand for Scanners#pattern.

Annotations
@SuppressWarnings:deprecation
Since
2.2