Package org.jparsec.pattern
Class Patterns
java.lang.Object
org.jparsec.pattern.Patterns
Provides common
Pattern
implementations.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Pattern
APattern
that always matches with match length0
.static final Pattern
APattern
that matches any character and only mismatches for an empty string.static final Pattern
APattern
object that matches a decimal integer, which starts with a non-zero digit and is followed by 0 or more digits.static final Pattern
APattern
object that matches a decimal number that could start with a decimal point or a digit.static final Pattern
APattern
object that matches if the input has no character left.static final Pattern
APattern
object that succeeds with match length2
if there are at least 2 characters in the input and the first character is'\'
.static final Pattern
APattern
object that matches a decimal point and one or more digits after it.static final Pattern
APattern
object that matches a hex integer, which starts with a0x
or0X
, and is followed by one or more hex digits.static final Pattern
APattern
object that matches an integer.static final Pattern
APattern
that always returnsPattern.MISMATCH
.static final Pattern
APattern
object that matches an octal integer that starts with a0
and is followed by 0 or more[0 - 7]
characters.static final Pattern
APattern
object that matches regular expression modifiers, which is a list of alpha characters.static final Pattern
APattern
object that matches any regular expression pattern string in the form of/some pattern here/
.static final Pattern
static final Pattern
APattern
object that matches a decimal number that has at least one digit before the decimal point.static final Pattern
APattern
object 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 Pattern
Returns aPattern
object that matches if the current character in the input is equal to any character inchars
, in which case1
is returned as match length.static Pattern
Returns aPattern
that matches if all ofpatterns
matches, in which case, the maximum match length is returned.static Pattern
atLeast
(int min, CharPredicate predicate) Returns aPattern
object that matches if the input starts withmin
or more characters and all satisfypredicate
.static Pattern
atMost
(int max, CharPredicate predicate) private static Pattern
private static Pattern
static Pattern
hasAtLeast
(int n) Returns aPattern
object that matches if the input has at leastn
characters left.static Pattern
hasExact
(int n) Returns aPattern
object that matches if the input has exactlyn
characters left.static Pattern
isChar
(char c) Returns aPattern
object that matches if the current character in the input is equal to characterc
, in which case1
is returned as match length.static Pattern
isChar
(CharPredicate predicate) Returns aPattern
object that matches if the current character in the input satisfiespredicate
, in which case1
is returned as match length.static Pattern
lineComment
(String begin) Returns aPattern
object that matches a line comment started bybegin
and ended byEOF
orLF
(the line feed character).static Pattern
static Pattern
Returns aPattern
that tries all ofpatterns
, and picks the one with the longest match length.static Pattern
many
(int min, CharPredicate predicate) Deprecated.static Pattern
many
(CharPredicate predicate) Returns aPattern
that matches 0 or more characters satisfyingpredicate
.static Pattern
many1
(CharPredicate predicate) Returns aPattern
that matches 1 or more characters satisfyingpredicate
.private static int
matchMany
(CharPredicate predicate, CharSequence src, int len, int from, int acc) private static int
matchSome
(int max, CharPredicate predicate, CharSequence src, int len, int from, int acc) private static int
matchString
(String str, CharSequence src, int begin, int end) Matches (part of) a character sequence against a pattern string.private static int
matchStringCaseInsensitive
(String str, CharSequence src, int begin, int end) (package private) static Pattern
nextWithEmpty
(Pattern left, Pattern right) static Pattern
static Pattern
Returns aPattern
object that matches if the input has at least 1 character and doesn't matchstring
.static Pattern
notStringCaseInsensitive
(String string) Returns aPattern
object that matches if the input has at least 1 character and doesn't matchstring
case insensitively.(package private) static Pattern
static Pattern
Returns aPattern
that matches if any ofpatterns
matches, in which case, the first match length is returned.(package private) static Pattern
orWithoutEmpty
(Pattern left, Pattern right) static Pattern
range
(char c1, char c2) Returns aPattern
object that matches if the current character in the input is between characterc1
andc2
, in which case1
is returned as match length.static Pattern
Adapts a regular expression pattern string to aPattern
.static Pattern
Adapts a regular expression pattern to aPattern
.static Pattern
repeat
(int n, CharPredicate predicate) Returns aPattern
object that matches if the input has at leastn
characters and the firstn
characters all satisfypredicate
.static Pattern
Returns aPattern
object that matches the input againstpatterns
sequentially.static Pattern
static Pattern
Returns aPattern
that tries all ofpatterns
, and picks the one with the shortest match length.static Pattern
some
(int min, int max, CharPredicate predicate) Deprecated.Usetimes(int, int, CharPredicate)
instead.static Pattern
some
(int max, CharPredicate predicate) Deprecated.UseatMost(int, CharPredicate)
instead.static Pattern
Returns aPattern
object that matchesstring
literally.static Pattern
stringCaseInsensitive
(String string) Returns aPattern
object that matchesstring
case insensitively.static Pattern
times
(int min, int max, CharPredicate predicate) Returns aPattern
that matches at leastmin
and up tomax
number of characters satisfyingpredicate
,
-
Field Details
-
NEVER
APattern
that always returnsPattern.MISMATCH
. -
ALWAYS
APattern
that always matches with match length0
. -
ANY_CHAR
APattern
that matches any character and only mismatches for an empty string. -
EOF
APattern
object that matches if the input has no character left. Match length is0
if succeed. -
ESCAPED
APattern
object that succeeds with match length2
if there are at least 2 characters in the input and the first character is'\'
. Mismatch otherwise. -
INTEGER
APattern
object that matches an integer. -
STRICT_DECIMAL
APattern
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
APattern
object that matches a decimal point and one or more digits after it. -
DECIMAL
APattern
object that matches a decimal number that could start with a decimal point or a digit. -
WORD
APattern
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
APattern
object that matches an octal integer that starts with a0
and is followed by 0 or more[0 - 7]
characters. -
DEC_INTEGER
APattern
object that matches a decimal integer, which starts with a non-zero digit and is followed by 0 or more digits. -
HEX_INTEGER
APattern
object that matches a hex integer, which starts with a0x
or0X
, and is followed by one or more hex digits. -
SCIENTIFIC_NOTATION
-
REGEXP_PATTERN
APattern
object that matches any regular expression pattern string in the form of/some pattern here/
.'\'
is used as escape character. -
REGEXP_MODIFIERS
APattern
object that matches regular expression modifiers, which is a list of alpha characters.
-
-
Constructor Details
-
Patterns
private Patterns()
-
-
Method Details
-
hasAtLeast
Returns aPattern
object that matches if the input has at leastn
characters left. Match length isn
if succeed. -
hasExact
Returns aPattern
object that matches if the input has exactlyn
characters left. Match length isn
if succeed. -
isChar
Returns aPattern
object that matches if the current character in the input is equal to characterc
, in which case1
is returned as match length. Mismatches otherwise. -
range
Returns aPattern
object that matches if the current character in the input is between characterc1
andc2
, in which case1
is returned as match length. -
among
Returns aPattern
object that matches if the current character in the input is equal to any character inchars
, in which case1
is returned as match length. -
isChar
Returns aPattern
object that matches if the current character in the input satisfiespredicate
, in which case1
is returned as match length. -
lineComment
Returns aPattern
object that matches a line comment started bybegin
and ended byEOF
orLF
(the line feed character). -
string
Returns aPattern
object that matchesstring
literally. -
stringCaseInsensitive
Returns aPattern
object that matchesstring
case insensitively. -
notString
Returns aPattern
object that matches if the input has at least 1 character and doesn't matchstring
.1
is returned as match length if succeeds. -
notStringCaseInsensitive
Returns aPattern
object that matches if the input has at least 1 character and doesn't matchstring
case insensitively.1
is returned as match length if succeeds. -
not
- Parameters:
pattern
-- Returns:
- a
Pattern
that matches iff the input does not match nestedpattern
.
-
and
Returns aPattern
that matches if all ofpatterns
matches, in which case, the maximum match length is returned. Mismatch if any one mismatches. -
or
Returns aPattern
that matches if any ofpatterns
matches, in which case, the first match length is returned. Mismatch if any one mismatches. -
orWithoutEmpty
-
nextWithEmpty
-
sequence
Returns aPattern
object that matches the input againstpatterns
sequentially. Te total match length is returned if all succeed. -
repeat
Returns aPattern
object that matches if the input has at leastn
characters and the firstn
characters all satisfypredicate
. -
many
Deprecated.UseatLeast(int, CharPredicate)
instead.Returns aPattern
object that matches if the input starts withmin
or more characters and all satisfypredicate
. -
atLeast
Returns aPattern
object that matches if the input starts withmin
or more characters and all satisfypredicate
.- Since:
- 2.2
-
many
Returns aPattern
that matches 0 or more characters satisfyingpredicate
. -
some
Deprecated.Usetimes(int, int, CharPredicate)
instead.Returns aPattern
that matches at leastmin
and up tomax
number of characters satisfyingpredicate
, -
times
Returns aPattern
that matches at leastmin
and up tomax
number of characters satisfyingpredicate
,- Since:
- 2.2
-
some
Deprecated.UseatMost(int, CharPredicate)
instead. -
atMost
- Since:
- 2.2
-
longer
Returns aPattern
that tries bothp1
andp2
, and picks the one with the longer match length. If both have the same length,p1
is favored. -
longest
Returns aPattern
that 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 aPattern
that tries bothp1
andp2
, and picks the one with the shorter match length. If both have the same length,p1
is favored. -
shortest
Returns aPattern
that 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 aPattern
that matches 1 or more characters satisfyingpredicate
. -
regex
Adapts a regular expression pattern to aPattern
.WARNING: in addition to regular expression cost, the returned
Pattern
object needs to make a substring copy every time it's evaluated. This can incur excessive copying and memory overhead when parsing large strings. Consider implementingPattern
manually for large input. -
regex
Adapts a regular expression pattern string to aPattern
.WARNING: in addition to regular expression cost, the returned
Pattern
object needs to make a substring copy every time it's evaluated. This can incur excessive copying and memory overhead when parsing large strings. Consider implementingPattern
manually 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.MISMATCH
if an unexpected character is encountered.
-
atLeast(int, CharPredicate)
instead.