public class CharRange extends java.lang.Object implements Matchable
Pattern
that matches a single character from some set or
range of characters. In regular expressions, such a pattern is written
with [ ...stuff... ]
Several commonly used ranges are provided as constants (e.g., DIGITS
) and
the CharRange.Builder
class can be used to construct simple and complex ranges.
Modifier and Type | Class and Description |
---|---|
static class |
CharRange.Builder
Instances of this class are used to incrementally build
CharRange s |
Modifier and Type | Field and Description |
---|---|
static CharRange |
ALL
A CharRange that matches any single character
|
static CharRange |
ASCIILOWER
Matches any ascii lower-case letter
|
static CharRange |
ASCIIUPPER
Matches any ascii upper-case letter
|
static CharRange |
ASCIIWHITE
Matches any ascii white space character (values from 0 to 32)
|
static CharRange |
DIGITS
A CharRange that matches any decimal digit (0-9)
|
static CharRange |
HEXDIGITS
A CharRange that matches any hexadecimal digit (0-9, a-f, and A-F)
|
static CharRange |
JAVA_ID_CHAR
Matches Java identifier characters
|
static CharRange |
JAVA_LETTER
Matches Java identifier start characters
|
static CharRange |
NONE
A CharRange that matches no characters.
|
static CharRange |
OCTALDIGITS
A CharRange that matches any octal digit (0-7)
|
Constructor and Description |
---|
CharRange(char in,
char out)
Create a CharRange that matches all characters with code points front in to out, inclusive.
|
Modifier and Type | Method and Description |
---|---|
int |
addToNFA(Nfa<?> nfa,
int targetState)
Add states to an NFA to match the desired pattern
|
static CharRange |
anyOf(java.lang.String chars)
Create a CharRange that matches any of the characters in the given string
|
static CharRange.Builder |
builder()
Create a CharRange.Builder
|
boolean |
contains(char c)
Check whether or not this range contains a character c
|
boolean |
equals(java.lang.Object r) |
CharRange |
getComplement()
Return a new CharRange that matches the characters that this one does not match.
|
Matchable |
getReversed()
Get the reverse of this pattern
|
int |
hashCode() |
boolean |
isUnbounded() |
boolean |
matchesEmpty() |
boolean |
matchesNonEmpty() |
boolean |
matchesSomething() |
static CharRange |
notAnyOf(java.lang.String chars)
Create a CharRange that matches any characters EXCEPT the characters in the given string
|
static CharRange |
range(char from,
char to)
Create a pattern that matches all single characters with a range of values
|
static CharRange |
single(char c)
Create a pattern that matches a single character
|
public static final CharRange ALL
public static final CharRange NONE
public static final CharRange DIGITS
public static final CharRange OCTALDIGITS
public static final CharRange HEXDIGITS
public static final CharRange ASCIILOWER
public static final CharRange ASCIIUPPER
public static final CharRange ASCIIWHITE
public static final CharRange JAVA_LETTER
public static final CharRange JAVA_ID_CHAR
public CharRange(char in, char out)
in
- one end of the character rangeout
- the other end of the character rangepublic boolean contains(char c)
c
- character to testpublic final CharRange getComplement()
public boolean equals(java.lang.Object r)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public boolean matchesEmpty()
matchesEmpty
in interface Matchable
public boolean matchesNonEmpty()
matchesNonEmpty
in interface Matchable
public boolean matchesSomething()
matchesSomething
in interface Matchable
public boolean isUnbounded()
isUnbounded
in interface Matchable
public Matchable getReversed()
Matchable
The reverse of a pattern matches the reverse of all the strings that this pattern matches
getReversed
in interface Matchable
public final int addToNFA(Nfa<?> nfa, int targetState)
Matchable
New states will be created in the NFA to match the pattern and transition to the given targetState.
NO NEW TRANSITIONS will be added to the target state or any other pre-existing state
addToNFA
in interface Matchable
nfa
- nfa to add totargetState
- target state after the pattern is matchedpublic static CharRange single(char c)
c
- character to matchpublic static CharRange range(char from, char to)
The pattern will match a character c if from <= c <= to.
from
- inclusive lower boundto
- inclusive upper boundpublic static CharRange anyOf(java.lang.String chars)
chars
- characters to matchpublic static CharRange notAnyOf(java.lang.String chars)
chars
- characters to excludepublic static CharRange.Builder builder()