Package org.jparsec.pattern
Class Patterns
java.lang.Object
org.jparsec.pattern.Patterns
Provides common
Pattern implementations.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PatternAPatternthat always matches with match length0.static final PatternAPatternthat matches any character and only mismatches for an empty string.static final PatternAPatternobject that matches a decimal integer, which starts with a non-zero digit and is followed by 0 or more digits.static final PatternAPatternobject that matches a decimal number that could start with a decimal point or a digit.static final PatternAPatternobject that matches if the input has no character left.static final PatternAPatternobject that succeeds with match length2if there are at least 2 characters in the input and the first character is'\'.static final PatternAPatternobject that matches a decimal point and one or more digits after it.static final PatternAPatternobject that matches a hex integer, which starts with a0xor0X, and is followed by one or more hex digits.static final PatternAPatternobject that matches an integer.static final PatternAPatternthat always returnsPattern.MISMATCH.static final PatternAPatternobject that matches an octal integer that starts with a0and is followed by 0 or more[0 - 7]characters.static final PatternAPatternobject that matches regular expression modifiers, which is a list of alpha characters.static final PatternAPatternobject that matches any regular expression pattern string in the form of/some pattern here/.static final Patternstatic final PatternAPatternobject that matches a decimal number that has at least one digit before the decimal point.static final PatternAPatternobject that matches a standard english word, which starts with either an underscore or an alpha character, followed by 0 or more alphanumeric characters. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PatternReturns aPatternobject that matches if the current character in the input is equal to any character inchars, in which case1is returned as match length.static PatternReturns aPatternthat matches if all ofpatternsmatches, in which case, the maximum match length is returned.static PatternatLeast(int min, CharPredicate predicate) Returns aPatternobject that matches if the input starts withminor more characters and all satisfypredicate.static PatternatMost(int max, CharPredicate predicate) private static Patternprivate static Patternstatic PatternhasAtLeast(int n) Returns aPatternobject that matches if the input has at leastncharacters left.static PatternhasExact(int n) Returns aPatternobject that matches if the input has exactlyncharacters left.static PatternisChar(char c) Returns aPatternobject that matches if the current character in the input is equal to characterc, in which case1is returned as match length.static PatternisChar(CharPredicate predicate) Returns aPatternobject that matches if the current character in the input satisfiespredicate, in which case1is returned as match length.static PatternlineComment(String begin) Returns aPatternobject that matches a line comment started bybeginand ended byEOForLF(the line feed character).static Patternstatic PatternReturns aPatternthat tries all ofpatterns, and picks the one with the longest match length.static Patternmany(int min, CharPredicate predicate) Deprecated.static Patternmany(CharPredicate predicate) Returns aPatternthat matches 0 or more characters satisfyingpredicate.static Patternmany1(CharPredicate predicate) Returns aPatternthat matches 1 or more characters satisfyingpredicate.private static intmatchMany(CharPredicate predicate, CharSequence src, int len, int from, int acc) private static intmatchSome(int max, CharPredicate predicate, CharSequence src, int len, int from, int acc) private static intmatchString(String str, CharSequence src, int begin, int end) Matches (part of) a character sequence against a pattern string.private static intmatchStringCaseInsensitive(String str, CharSequence src, int begin, int end) (package private) static PatternnextWithEmpty(Pattern left, Pattern right) static Patternstatic PatternReturns aPatternobject that matches if the input has at least 1 character and doesn't matchstring.static PatternnotStringCaseInsensitive(String string) Returns aPatternobject that matches if the input has at least 1 character and doesn't matchstringcase insensitively.(package private) static Patternstatic PatternReturns aPatternthat matches if any ofpatternsmatches, in which case, the first match length is returned.(package private) static PatternorWithoutEmpty(Pattern left, Pattern right) static Patternrange(char c1, char c2) Returns aPatternobject that matches if the current character in the input is between characterc1andc2, in which case1is returned as match length.static PatternAdapts a regular expression pattern string to aPattern.static PatternAdapts a regular expression pattern to aPattern.static Patternrepeat(int n, CharPredicate predicate) Returns aPatternobject that matches if the input has at leastncharacters and the firstncharacters all satisfypredicate.static PatternReturns aPatternobject that matches the input againstpatternssequentially.static Patternstatic PatternReturns aPatternthat tries all ofpatterns, and picks the one with the shortest match length.static Patternsome(int min, int max, CharPredicate predicate) Deprecated.Usetimes(int, int, CharPredicate)instead.static Patternsome(int max, CharPredicate predicate) Deprecated.UseatMost(int, CharPredicate)instead.static PatternReturns aPatternobject that matchesstringliterally.static PatternstringCaseInsensitive(String string) Returns aPatternobject that matchesstringcase insensitively.static Patterntimes(int min, int max, CharPredicate predicate) Returns aPatternthat matches at leastminand up tomaxnumber of characters satisfyingpredicate,
-
Field Details
-
NEVER
APatternthat always returnsPattern.MISMATCH. -
ALWAYS
APatternthat always matches with match length0. -
ANY_CHAR
APatternthat matches any character and only mismatches for an empty string. -
EOF
APatternobject that matches if the input has no character left. Match length is0if succeed. -
ESCAPED
APatternobject that succeeds with match length2if there are at least 2 characters in the input and the first character is'\'. Mismatch otherwise. -
INTEGER
APatternobject that matches an integer. -
STRICT_DECIMAL
APatternobject 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.3are all good candidates. While.1, .are not. -
FRACTION
APatternobject that matches a decimal point and one or more digits after it. -
DECIMAL
APatternobject that matches a decimal number that could start with a decimal point or a digit. -
WORD
APatternobject 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
APatternobject that matches an octal integer that starts with a0and is followed by 0 or more[0 - 7]characters. -
DEC_INTEGER
APatternobject that matches a decimal integer, which starts with a non-zero digit and is followed by 0 or more digits. -
HEX_INTEGER
APatternobject that matches a hex integer, which starts with a0xor0X, and is followed by one or more hex digits. -
SCIENTIFIC_NOTATION
-
REGEXP_PATTERN
APatternobject that matches any regular expression pattern string in the form of/some pattern here/.'\'is used as escape character. -
REGEXP_MODIFIERS
APatternobject that matches regular expression modifiers, which is a list of alpha characters.
-
-
Constructor Details
-
Patterns
private Patterns()
-
-
Method Details
-
hasAtLeast
Returns aPatternobject that matches if the input has at leastncharacters left. Match length isnif succeed. -
hasExact
Returns aPatternobject that matches if the input has exactlyncharacters left. Match length isnif succeed. -
isChar
Returns aPatternobject that matches if the current character in the input is equal to characterc, in which case1is returned as match length. Mismatches otherwise. -
range
Returns aPatternobject that matches if the current character in the input is between characterc1andc2, in which case1is returned as match length. -
among
Returns aPatternobject that matches if the current character in the input is equal to any character inchars, in which case1is returned as match length. -
isChar
Returns aPatternobject that matches if the current character in the input satisfiespredicate, in which case1is returned as match length. -
lineComment
Returns aPatternobject that matches a line comment started bybeginand ended byEOForLF(the line feed character). -
string
Returns aPatternobject that matchesstringliterally. -
stringCaseInsensitive
Returns aPatternobject that matchesstringcase insensitively. -
notString
Returns aPatternobject that matches if the input has at least 1 character and doesn't matchstring.1is returned as match length if succeeds. -
notStringCaseInsensitive
Returns aPatternobject that matches if the input has at least 1 character and doesn't matchstringcase insensitively.1is returned as match length if succeeds. -
not
- Parameters:
pattern-- Returns:
- a
Patternthat matches iff the input does not match nestedpattern.
-
and
Returns aPatternthat matches if all ofpatternsmatches, in which case, the maximum match length is returned. Mismatch if any one mismatches. -
or
Returns aPatternthat matches if any ofpatternsmatches, in which case, the first match length is returned. Mismatch if any one mismatches. -
orWithoutEmpty
-
nextWithEmpty
-
sequence
Returns aPatternobject that matches the input againstpatternssequentially. Te total match length is returned if all succeed. -
repeat
Returns aPatternobject that matches if the input has at leastncharacters and the firstncharacters all satisfypredicate. -
many
Deprecated.UseatLeast(int, CharPredicate)instead.Returns aPatternobject that matches if the input starts withminor more characters and all satisfypredicate. -
atLeast
Returns aPatternobject that matches if the input starts withminor more characters and all satisfypredicate.- Since:
- 2.2
-
many
Returns aPatternthat matches 0 or more characters satisfyingpredicate. -
some
Deprecated.Usetimes(int, int, CharPredicate)instead.Returns aPatternthat matches at leastminand up tomaxnumber of characters satisfyingpredicate, -
times
Returns aPatternthat matches at leastminand up tomaxnumber of characters satisfyingpredicate,- Since:
- 2.2
-
some
Deprecated.UseatMost(int, CharPredicate)instead. -
atMost
- Since:
- 2.2
-
longer
Returns aPatternthat tries bothp1andp2, and picks the one with the longer match length. If both have the same length,p1is favored. -
longest
Returns aPatternthat tries all ofpatterns, and picks the one with the longest match length. If two patterns have the same length, the first one is favored. -
shorter
Returns aPatternthat tries bothp1andp2, and picks the one with the shorter match length. If both have the same length,p1is favored. -
shortest
Returns aPatternthat tries all ofpatterns, and picks the one with the shortest match length. If two patterns have the same length, the first one is favored. -
many1
Returns aPatternthat matches 1 or more characters satisfyingpredicate. -
regex
Adapts a regular expression pattern to aPattern.WARNING: in addition to regular expression cost, the returned
Patternobject needs to make a substring copy every time it's evaluated. This can incur excessive copying and memory overhead when parsing large strings. Consider implementingPatternmanually for large input. -
regex
Adapts a regular expression pattern string to aPattern.WARNING: in addition to regular expression cost, the returned
Patternobject needs to make a substring copy every time it's evaluated. This can incur excessive copying and memory overhead when parsing large strings. Consider implementingPatternmanually for large input. -
optional
-
matchSome
private static int matchSome(int max, CharPredicate predicate, CharSequence src, int len, int from, int acc) -
getRegularExpressionPattern
-
getModifiersPattern
-
matchMany
-
matchStringCaseInsensitive
-
matchString
Matches (part of) a character sequence against a pattern string.- Parameters:
str- the pattern string.src- the input sequence. Must not be null.begin- start of index to scan characters fromsrc.end- end of index to scan characters fromsrc.- Returns:
- the number of characters matched, or
Pattern.MISMATCHif an unexpected character is encountered.
-
atLeast(int, CharPredicate)instead.