org.codehaus.jparsec.pattern
Class Patterns

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

public final class Patterns
extends Object

Provides common Pattern implementations.

Author:
Ben Yu

Field Summary
static Pattern ALWAYS
          A Pattern that always matches with match length 0.
static Pattern ANY_CHAR
          A Pattern that matches any character and only mismatches for an empty string.
static Pattern DEC_INTEGER
          A Pattern object that matches a decimal integer, which starts with a non-zero digit and is followed by 0 or more digits.
static Pattern DECIMAL
          A Pattern object that matches a decimal number that could start with a decimal point or a digit.
static Pattern EOF
          A Pattern object that matches if the input has no character left.
static Pattern ESCAPED
          A Pattern object that succeeds with match length 2 if there are at least 2 characters in the input and the first character is '\'.
static Pattern FRACTION
          A Pattern object that matches a decimal point and one or more digits after it.
static Pattern HEX_INTEGER
          A Pattern object that matches a hex integer, which starts with a 0x or 0X, and is followed by one or more hex digits.
static Pattern INTEGER
          A Pattern object that matches an integer.
static Pattern NEVER
          A Pattern that always returns Pattern.MISMATCH.
static Pattern OCT_INTEGER
          A Pattern object that matches an octal integer that starts with a 0 and is followed by 0 or more [0 - 7] characters.
static Pattern REGEXP_MODIFIERS
          A Pattern object that matches regular expression modifiers, which is a list of alpha characters.
static Pattern REGEXP_PATTERN
          A Pattern object that matches any regular expression pattern string in the form of /some pattern here/.
static Pattern SCIENTIFIC_NOTATION
          A Pattern object that matches a scientific notation, such as 1e12, 1.2E-1, etc.
static Pattern STRICT_DECIMAL
          A Pattern object that matches a decimal number that has at least one digit before the decimal point.
static Pattern WORD
          A Pattern object that matches a standard english word, which starts with either an underscore or an alpha character, followed by 0 or more alphanumeric characters.
 
Method Summary
static Pattern among(String chars)
          Returns a Pattern object that matches if the current character in the input is equal to any character in chars, in which case 1 is returned as match length.
static Pattern and(Pattern... patterns)
          Returns a Pattern that matches if all of patterns matches, in which case, the maximum match length is returned.
static Pattern atLeast(int min, CharPredicate predicate)
          Returns a Pattern object that matches if the input starts with min or more characters and all satisfy predicate.
static Pattern atMost(int max, CharPredicate predicate)
          Returns a Pattern that matches up to max number of characters satisfying predicate.
static Pattern hasAtLeast(int n)
          Returns a Pattern object that matches if the input has at least n characters left.
static Pattern hasExact(int n)
          Returns a Pattern object that matches if the input has exactly n characters left.
static Pattern isChar(char c)
          Returns a Pattern object that matches if the current character in the input is equal to character c, in which case 1 is returned as match length.
static Pattern isChar(CharPredicate predicate)
          Returns a Pattern object that matches if the current character in the input satisfies predicate, in which case 1 is returned as match length.
static Pattern lineComment(String begin)
          Returns a Pattern object that matches a line comment started by begin and ended by EOF or LF (the line feed character).
static Pattern longer(Pattern p1, Pattern p2)
          Returns a Pattern that tries both p1 and p2, and picks the one with the longer match length.
static Pattern longest(Pattern... patterns)
          Returns a Pattern that tries all of patterns, and picks the one with the longest match length.
static Pattern many(CharPredicate predicate)
          Returns a Pattern that matches 0 or more characters satisfying predicate.
static Pattern many(int min, CharPredicate predicate)
          Deprecated. Use atLeast(int, CharPredicate) instead.
static Pattern many1(CharPredicate predicate)
          Returns a Pattern that matches 1 or more characters satisfying predicate.
static Pattern not(Pattern pattern)
           
static Pattern notString(String string)
          Returns a Pattern object that matches if the input has at least 1 character and doesn't match string.
static Pattern notStringCaseInsensitive(String string)
          Returns a Pattern object that matches if the input has at least 1 character and doesn't match string case insensitively.
static Pattern or(Pattern... patterns)
          Returns a Pattern that matches if any of patterns matches, in which case, the first match length is returned.
static Pattern range(char c1, char c2)
          Returns a Pattern object that matches if the current character in the input is between character c1 and c2, in which case 1 is returned as match length.
static Pattern regex(Pattern p)
          Adapts a regular expression pattern to a Pattern.
static Pattern regex(String s)
          Adapts a regular expression pattern string to a Pattern.
static Pattern repeat(int n, CharPredicate predicate)
          Returns a Pattern object that matches if the input has at least n characters and the first n characters all satisfy predicate.
static Pattern sequence(Pattern... patterns)
          Returns a Pattern object that matches the input against patterns sequentially.
static Pattern shorter(Pattern p1, Pattern p2)
          Returns a Pattern that tries both p1 and p2, and picks the one with the shorter match length.
static Pattern shortest(Pattern... patterns)
          Returns a Pattern that tries all of patterns, and picks the one with the shortest match length.
static Pattern some(int max, CharPredicate predicate)
          Deprecated. Use atMost(int, CharPredicate) instead.
static Pattern some(int min, int max, CharPredicate predicate)
          Deprecated. Use times(int, int, CharPredicate) instead.
static Pattern string(String string)
          Returns a Pattern object that matches string literally.
static Pattern stringCaseInsensitive(String string)
          Returns a Pattern object that matches string case insensitively.
static Pattern times(int min, int max, CharPredicate predicate)
          Returns a Pattern that matches at least min and up to max number of characters satisfying predicate,
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NEVER

public static final Pattern NEVER
A Pattern that always returns Pattern.MISMATCH.


ALWAYS

public static final Pattern ALWAYS
A Pattern that always matches with match length 0.


ANY_CHAR

public static final Pattern ANY_CHAR
A Pattern that matches any character and only mismatches for an empty string.


EOF

public static final Pattern EOF
A Pattern object that matches if the input has no character left. Match length is 0 if succeed.


ESCAPED

public static final Pattern ESCAPED
A Pattern object that succeeds with match length 2 if there are at least 2 characters in the input and the first character is '\'. Mismatch otherwise.


INTEGER

public static final Pattern INTEGER
A Pattern object that matches an integer.


STRICT_DECIMAL

public static final Pattern STRICT_DECIMAL
A Pattern object that matches a decimal number that has at least one digit before the decimal point. The decimal point and the numbers to the right are optional.

0, 11., 2.3 are all good candidates. While .1, . are not.


FRACTION

public static final Pattern FRACTION
A Pattern object that matches a decimal point and one or more digits after it.


DECIMAL

public static final Pattern DECIMAL
A Pattern object that matches a decimal number that could start with a decimal point or a digit.


WORD

public static final Pattern WORD
A Pattern object that matches a standard english word, which starts with either an underscore or an alpha character, followed by 0 or more alphanumeric characters.


OCT_INTEGER

public static final Pattern OCT_INTEGER
A Pattern object that matches an octal integer that starts with a 0 and is followed by 0 or more [0 - 7] characters.


DEC_INTEGER

public static final Pattern DEC_INTEGER
A Pattern object that matches a decimal integer, which starts with a non-zero digit and is followed by 0 or more digits.


HEX_INTEGER

public static final Pattern HEX_INTEGER
A Pattern object that matches a hex integer, which starts with a 0x or 0X, and is followed by one or more hex digits.


SCIENTIFIC_NOTATION

public static final Pattern SCIENTIFIC_NOTATION
A Pattern object that matches a scientific notation, such as 1e12, 1.2E-1, etc.


REGEXP_PATTERN

public static final Pattern REGEXP_PATTERN
A Pattern object that matches any regular expression pattern string in the form of /some pattern here/. '\' is used as escape character.


REGEXP_MODIFIERS

public static final Pattern REGEXP_MODIFIERS
A Pattern object that matches regular expression modifiers, which is a list of alpha characters.

Method Detail

hasAtLeast

public static Pattern hasAtLeast(int n)
Returns a Pattern object that matches if the input has at least n characters left. Match length is n if succeed.


hasExact

public static Pattern hasExact(int n)
Returns a Pattern object that matches if the input has exactly n characters left. Match length is n if succeed.


isChar

public static Pattern isChar(char c)
Returns a Pattern object that matches if the current character in the input is equal to character c, in which case 1 is returned as match length. Mismatches otherwise.


range

public static Pattern range(char c1,
                            char c2)
Returns a Pattern object that matches if the current character in the input is between character c1 and c2, in which case 1 is returned as match length.


among

public static Pattern among(String chars)
Returns a Pattern object that matches if the current character in the input is equal to any character in chars, in which case 1 is returned as match length.


isChar

public static Pattern isChar(CharPredicate predicate)
Returns a Pattern object that matches if the current character in the input satisfies predicate, in which case 1 is returned as match length.


lineComment

public static Pattern lineComment(String begin)
Returns a Pattern object that matches a line comment started by begin and ended by EOF or LF (the line feed character).


string

public static Pattern string(String string)
Returns a Pattern object that matches string literally.


stringCaseInsensitive

public static Pattern stringCaseInsensitive(String string)
Returns a Pattern object that matches string case insensitively.


notString

public static Pattern notString(String string)
Returns a Pattern object that matches if the input has at least 1 character and doesn't match string. 1 is returned as match length if succeeds.


notStringCaseInsensitive

public static Pattern notStringCaseInsensitive(String string)
Returns a Pattern object that matches if the input has at least 1 character and doesn't match string case insensitively. 1 is returned as match length if succeeds.


not

public static Pattern not(Pattern pattern)
Parameters:
pattern -
Returns:
a Pattern that matches iff the input does not match nested pattern.

and

public static Pattern and(Pattern... patterns)
Returns a Pattern that matches if all of patterns matches, in which case, the maximum match length is returned. Mismatch if any one mismatches.


or

public static Pattern or(Pattern... patterns)
Returns a Pattern that matches if any of patterns matches, in which case, the first match length is returned. Mismatch if any one mismatches.


sequence

public static Pattern sequence(Pattern... patterns)
Returns a Pattern object that matches the input against patterns sequentially. Te total match length is returned if all succeed.


repeat

public static Pattern repeat(int n,
                             CharPredicate predicate)
Returns a Pattern object that matches if the input has at least n characters and the first n characters all satisfy predicate.


many

@Deprecated
public static Pattern many(int min,
                                      CharPredicate predicate)
Deprecated. Use atLeast(int, CharPredicate) instead.

Returns a Pattern object that matches if the input starts with min or more characters and all satisfy predicate.


atLeast

public static Pattern atLeast(int min,
                              CharPredicate predicate)
Returns a Pattern object that matches if the input starts with min or more characters and all satisfy predicate.

Since:
2.2

many

public static Pattern many(CharPredicate predicate)
Returns a Pattern that matches 0 or more characters satisfying predicate.


some

@Deprecated
public static Pattern some(int min,
                                      int max,
                                      CharPredicate predicate)
Deprecated. Use times(int, int, CharPredicate) instead.

Returns a Pattern that matches at least min and up to max number of characters satisfying predicate,


times

public static Pattern times(int min,
                            int max,
                            CharPredicate predicate)
Returns a Pattern that matches at least min and up to max number of characters satisfying predicate,

Since:
2.2

some

@Deprecated
public static Pattern some(int max,
                                      CharPredicate predicate)
Deprecated. Use atMost(int, CharPredicate) instead.

Returns a Pattern that matches up to max number of characters satisfying predicate.


atMost

public static Pattern atMost(int max,
                             CharPredicate predicate)
Returns a Pattern that matches up to max number of characters satisfying predicate.

Since:
2.2

longer

public static Pattern longer(Pattern p1,
                             Pattern p2)
Returns a Pattern that tries both p1 and p2, and picks the one with the longer match length. If both have the same length, p1 is favored.


longest

public static Pattern longest(Pattern... patterns)
Returns a Pattern that tries all of patterns, and picks the one with the longest match length. If two patterns have the same length, the first one is favored.


shorter

public static Pattern shorter(Pattern p1,
                              Pattern p2)
Returns a Pattern that tries both p1 and p2, and picks the one with the shorter match length. If both have the same length, p1 is favored.


shortest

public static Pattern shortest(Pattern... patterns)
Returns a Pattern that tries all of patterns, and picks the one with the shortest match length. If two patterns have the same length, the first one is favored.


many1

public static Pattern many1(CharPredicate predicate)
Returns a Pattern that matches 1 or more characters satisfying predicate.


regex

public static Pattern regex(Pattern p)
Adapts a regular expression pattern to a Pattern.


regex

public static Pattern regex(String s)
Adapts a regular expression pattern string to a Pattern.



Copyright © 2014. All rights reserved.