Package org.apache.commons.cli
Class OptionValidator
- java.lang.Object
-
- org.apache.commons.cli.OptionValidator
-
final class OptionValidator extends java.lang.ObjectValidates an Option string.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static char[]ADDITIONAL_LONG_CHARSThe array of additional characters allowed in the rest of the option but not in the first position(package private) static char[]ADDITIONAL_OPTION_CHARSThe array of additional characters allowed as the first character in the option but not in the rest of the option
-
Constructor Summary
Constructors Constructor Description OptionValidator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static booleanisValidChar(char c)Returns whether the specified character is a valid character.private static booleanisValidOpt(char c)Returns whether the specified character is a valid Option.private static booleansearch(char[] chars, char c)Checks the char array for a matching char.(package private) static java.lang.Stringvalidate(java.lang.String option)Validates whetheroptis a permissible Option shortOpt.
-
-
-
Field Detail
-
ADDITIONAL_OPTION_CHARS
static final char[] ADDITIONAL_OPTION_CHARS
The array of additional characters allowed as the first character in the option but not in the rest of the option
-
ADDITIONAL_LONG_CHARS
static final char[] ADDITIONAL_LONG_CHARS
The array of additional characters allowed in the rest of the option but not in the first position
-
-
Method Detail
-
isValidChar
private static boolean isValidChar(char c)
Returns whether the specified character is a valid character. A character is valid if any of the following conditions are true:- it is a letter
- it is a currency symbol (such as '$')
- it is a connecting punctuation character (such as '_')
- it is a digit
- it is a numeric letter (such as a Roman numeral character)
- it is a combining mark
- it is a non-spacing mark
- isIdentifierIgnorable returns true for the character
- it is a hyphen/dash ('-')
- Parameters:
c- the character to validate- Returns:
- true if
cis a valid character letter.
-
isValidOpt
private static boolean isValidOpt(char c)
Returns whether the specified character is a valid Option. A character is valid if any of the following conditions are true:- it is a letter
- it is a currency symbol (such as '$')
- it is a connecting punctuation character (such as '_')
- it is a digit
- it is a numeric letter (such as a Roman numeral character)
- it is a combining mark
- it is a non-spacing mark
- isIdentifierIgnorable returns true for the character
- it is a question mark or 'at' sign ('?' or '@')
- Parameters:
c- the option to validate- Returns:
- true if
cis a letter, '?' or '@', otherwise false.
-
search
private static boolean search(char[] chars, char c)Checks the char array for a matching char.- Parameters:
chars- the char array to searchc- the char to look for.- Returns:
trueifcwas inary,falseotherwise.
-
validate
static java.lang.String validate(java.lang.String option) throws java.lang.IllegalArgumentExceptionValidates whetheroptis a permissible Option shortOpt. The rules that specify if theoptis valid are:- a single character
optthat is either Chars.SP(special case), '?', '@' or a letter - a multi character
optthat only contains valid characters
A character is valid if any of the following conditions are true:
- it is a letter
- it is a currency symbol (such as '$')
- it is a connecting punctuation character (such as '_')
- it is a digit
- it is a numeric letter (such as a Roman numeral character)
- it is a combining mark
- it is a non-spacing mark
- isIdentifierIgnorable returns true for the character
- it is a hyphen/dash ('-')
In case
optisnullno further validation is performed.- Parameters:
option- The option string to validate, may be null.- Throws:
java.lang.IllegalArgumentException- if the Option is not valid.
- a single character
-
-