. Short options with more than one character are not allowed as
well as long options with just one character (but parameters are allowed).
Since: 0.2
Version: $Revision: 1.4 $ $Date: 2001/12/20 14:42:56 $
Author: Andreas Rummler
Method Summary
protected int
containsEqualSign (java.lang.String s)
Checks if this string contains an equal sign.
protected java.lang.String[]
getKeyValue (java.lang.String s,
int equalSignIndex)
Extracts option and value from a string.
protected java.lang.String
getLongOption (java.lang.String s)
Returns the long option from an option string.
protected java.lang.String
getShortOption (java.lang.String s)
Returns the short option from an option string.
protected boolean
isLetter (char c)
Checks if this character is a letter.
protected boolean
isWord (java.lang.String s)
Checks if the given string contains only characters of a "-" sign.
void
parse (java.lang.String commandLine)
Parses the given string.
void
parse (java.lang.String[] commandLine)
Parses the given array of strings.
protected void
parseCommand (java.util.LinkedList tokenList)
Detects the command from the input tokens.
protected void
parseOptions (java.util.LinkedList tokenList)
Extracts the options from the token lists.
protected void
storeOption (java.lang.String key,
java.lang.String value)
Stores the found options and values in the internal hashtable.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
CommandLineParser
public CommandLineParser ()
parse
public void parse (java.lang.String[] commandLine)
throws CommandLineParserException
Parses the given array of strings.
Parameters: commandLine
- array of strings to parseThrows: CommandLineParserException
- thrown in case parsing fails
parse
public void parse (java.lang.String commandLine)
throws CommandLineParserException
Parses the given string.
Parameters: commandLine
- string to parseThrows: CommandLineParserException
- thrown in case parsing fails
parseCommand
protected void parseCommand (java.util.LinkedList tokenList)
throws CommandLineParserException
Detects the command from the input tokens.
Parameters: tokenList
- string token listThrows: CommandLineParserException
- thrown in case the last token in the
list is not a valid command
parseOptions
protected void parseOptions (java.util.LinkedList tokenList)
throws CommandLineParserException
Extracts the options from the token lists.
Parameters: tokenList
- list of string tokensThrows: CommandLineParserException
- thrown in case the parsing fails
getLongOption
protected java.lang.String getLongOption (java.lang.String s)
Returns the long option from an option string.
This checks if the given string starts with "--" and has a length greater 3.
Parameters: s
- string to check for being a long optionReturns: returns the long option minus the starting "--", null if the given
string is not a long option
getShortOption
protected java.lang.String getShortOption (java.lang.String s)
Returns the short option from an option string.
This checks if the given string starts with "-" and has a length greater 1.
Parameters: s
- string to check for being a short optionReturns: returns the short option minus the starting "-", null if the given
string is not a short option
getKeyValue
protected java.lang.String[] getKeyValue (java.lang.String s,
int equalSignIndex)
Extracts option and value from a string.
The string is cut into two pieces, from start to the given index and from index to end.
Parameters: s
- string to break upequalSignIndex
- index of the equals signReturns: key and value contained in an array
isWord
protected boolean isWord (java.lang.String s)
Checks if the given string contains only characters of a "-" sign.
Parameters: s
- string to checkReturns: result of the check
isLetter
protected boolean isLetter (char c)
Checks if this character is a letter.
Parameters: c
- character to checkReturns: result of the test
containsEqualSign
protected int containsEqualSign (java.lang.String s)
Checks if this string contains an equal sign.
Parameters: s
- string to checkReturns: index of the found equals sign, or -1 instead
storeOption
protected void storeOption (java.lang.String key,
java.lang.String value)
Stores the found options and values in the internal hashtable.
Parameters: key
- key to storevalue
- value to store
Copyright © 2000-2001 Technical University of Ilmenau, Department ESS