org.codehaus.jparsec.pattern
Class Pattern

java.lang.Object
  extended by org.codehaus.jparsec.pattern.Pattern

public abstract class Pattern
extends Object

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
static int MISMATCH
          Returned by match(CharSequence, int, int) method when match fails.
 
Constructor Summary
Pattern()
           
 
Method Summary
 Pattern atLeast(int min)
          Returns Pattern object that matches this pattern for at least min times.
 Pattern atMost(int max)
          Returns Pattern object that matches this pattern for up to max times.
 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.
 Pattern many()
          Returns a Pattern object that matches this pattern for 0 or more times.
 Pattern many(int min)
          Deprecated. Use atLeast(int) instead.
 Pattern many1()
          Returns a Pattern 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.
 Pattern next(Pattern next)
          Returns a Pattern object that sequentially matches the character range against this and then next.
 Pattern not()
          Returns a Pattern object that only matches if this pattern mismatches, 0 is returned otherwise.
 Pattern optional()
          Returns a Pattern object that matches with 0 length even if this mismatches.
 Pattern or(Pattern p2)
          Returns Pattern object that matches if either this or p2 matches.
 Pattern peek()
          Returns Pattern object that matches with match length 0 if this Pattern object matches.
 Pattern repeat(int n)
          Deprecated. Use times(int) instead.
 Pattern some(int max)
          Deprecated. Use atMost(int) instead.
 Pattern some(int min, int max)
          Deprecated. Use times(int, int) instead.
 Pattern times(int n)
          Returns Pattern object that matches the input against this pattern for n times.
 Pattern times(int min, int max)
          Returns Pattern object that matches this pattern for at least min times and up to max times.
 Parser<Void> toScanner(String name)
          Returns a scanner parser using this pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MISMATCH

public static final int MISMATCH
Returned by match(CharSequence, int, int) method when match fails.

See Also:
Constant Field Values
Constructor Detail

Pattern

public Pattern()
Method Detail

match

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 - 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 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 - the next pattern to match.
Returns:
the new Pattern object.

optional

public final Pattern optional()
Returns a Pattern object that matches with 0 length even if this mismatches.


many

public final Pattern many()
Returns a Pattern 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. Use atLeast(int) instead.

Returns Pattern object that matches this pattern for at least min 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)
Returns Pattern object that matches this pattern for at least min 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 a Pattern 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. Use atMost(int) instead.

Returns Pattern object that matches this pattern for up to max 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)
Returns Pattern object that matches this pattern for up to max 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. 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 - 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)
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 - 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 a Pattern object that only matches if this pattern mismatches, 0 is returned otherwise.


peek

public final Pattern peek()
Returns Pattern object that matches with match length 0 if this Pattern object matches.


ifelse

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.


repeat

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

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


times

public final Pattern times(int n)
Returns Pattern object that matches the input against this pattern for n times.

Since:
2.2

or

public final Pattern or(Pattern p2)
Returns Pattern object that matches if either this or p2 matches.


toScanner

public final Parser<Void> toScanner(String name)
Returns a scanner parser using this pattern. Convenient short-hand for Scanners.pattern(org.codehaus.jparsec.pattern.Pattern, java.lang.String).

Since:
2.2


Copyright © 2014. All rights reserved.