@AnnotatedFor(value="nullness") public final class RegexUtil extends Object
For an example of intended use, see section Testing whether a string is a regular expression in the Checker Framework manual.
Runtime Dependency: If you use this class, you must distribute (or link to) checker-qual.jar
, along with your binaries. Or, you can can copy this class into your own
project.
Modifier and Type | Class and Description |
---|---|
static class |
RegexUtil.CheckedPatternSyntaxException
A checked version of
PatternSyntaxException . |
Modifier and Type | Method and Description |
---|---|
static @Regex String |
asRegex(String s)
Returns the argument as a
@Regex String if it is a regex, otherwise throws an error. |
static @Regex String |
asRegex(String s,
int groups)
Returns the argument as a
@Regex(groups) String if it is a regex with at least the
given number of groups, otherwise throws an error. |
static boolean |
isRegex(char c)
Returns true if the argument is a syntactically valid regular expression.
|
static boolean |
isRegex(String s)
Returns true if the argument is a syntactically valid regular expression.
|
static boolean |
isRegex(String s,
int groups)
Returns true if the argument is a syntactically valid regular expression with at least the
given number of groups.
|
static @Nullable String |
regexError(String s)
Returns null if the argument is a syntactically valid regular expression.
|
static @Nullable String |
regexError(String s,
int groups)
Returns null if the argument is a syntactically valid regular expression with at least the
given number of groups.
|
static @Nullable PatternSyntaxException |
regexException(String s)
Returns null if the argument is a syntactically valid regular expression.
|
static @Nullable PatternSyntaxException |
regexException(String s,
int groups)
Returns null if the argument is a syntactically valid regular expression with at least the
given number of groups.
|
@Pure @EnsuresQualifierIf(result=true, expression="#1", qualifier=Regex.class) public static boolean isRegex(String s)
s
- string to check for being a regular expression@Pure @EnsuresQualifierIf(result=true, expression="#1", qualifier=Regex.class) public static boolean isRegex(String s, int groups)
s
- string to check for being a regular expressiongroups
- number of groups expectedgroups
groups@Pure @EnsuresQualifierIf(result=true, expression="#1", qualifier=Regex.class) public static boolean isRegex(char c)
c
- char to check for being a regular expression@SideEffectFree public static @Nullable String regexError(String s)
s
- string to check for being a regular expression@SideEffectFree public static @Nullable String regexError(String s, int groups)
s
- string to check for being a regular expressiongroups
- number of groups expected@SideEffectFree public static @Nullable PatternSyntaxException regexException(String s)
s
- string to check for being a regular expression@SideEffectFree public static @Nullable PatternSyntaxException regexException(String s, int groups)
s
- string to check for being a regular expressiongroups
- number of groups expected@SideEffectFree public static @Regex String asRegex(String s)
@Regex String
if it is a regex, otherwise throws an error.
The purpose of this method is to suppress Regex Checker warnings. It should be very rarely needed.
s
- string to check for being a regular expressionError
- if argument is not a regex@SideEffectFree public static @Regex String asRegex(String s, int groups)
@Regex(groups) String
if it is a regex with at least the
given number of groups, otherwise throws an error.
The purpose of this method is to suppress Regex Checker warnings. It should be very rarely needed.
s
- string to check for being a regular expressiongroups
- number of groups expectedError
- if argument is not a regex