edu.rice.cs.util
Class ArgumentTokenizer

java.lang.Object
  extended by edu.rice.cs.util.ArgumentTokenizer

public abstract class ArgumentTokenizer
extends Object

Utility class which can tokenize a String into a list of String arguments, with behavior similar to parsing command line arguments to a program. Quoted Strings are treated as single arguments, and escaped characters are translated so that the tokenized arguments have the same meaning. Since all methods are static, the class is declared abstract to prevent instantiation.

Version:
$Id: ArgumentTokenizer.java 5175 2010-01-20 08:46:32Z mgricken $

Field Summary
private static int DOUBLE_QUOTE_STATE
           
private static int NO_TOKEN_STATE
           
private static int NORMAL_TOKEN_STATE
           
private static int SINGLE_QUOTE_STATE
           
 
Constructor Summary
ArgumentTokenizer()
           
 
Method Summary
protected static String _escapeQuotesAndBackslashes(String s)
          Inserts backslashes before any occurrences of a backslash or quote in the given string.
static List<String> tokenize(String arguments)
          Tokenizes the given String into String tokens
static List<String> tokenize(String arguments, boolean stringify)
          Tokenizes the given String into String tokens.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_TOKEN_STATE

private static final int NO_TOKEN_STATE
See Also:
Constant Field Values

NORMAL_TOKEN_STATE

private static final int NORMAL_TOKEN_STATE
See Also:
Constant Field Values

SINGLE_QUOTE_STATE

private static final int SINGLE_QUOTE_STATE
See Also:
Constant Field Values

DOUBLE_QUOTE_STATE

private static final int DOUBLE_QUOTE_STATE
See Also:
Constant Field Values
Constructor Detail

ArgumentTokenizer

public ArgumentTokenizer()
Method Detail

tokenize

public static List<String> tokenize(String arguments)
Tokenizes the given String into String tokens

Parameters:
arguments - A String containing one or more command-line style arguments to be tokenized.
Returns:
A list of parsed and properly escaped arguments.

tokenize

public static List<String> tokenize(String arguments,
                                    boolean stringify)
Tokenizes the given String into String tokens.

Parameters:
arguments - A String containing one or more command-line style arguments to be tokenized.
stringify - whether or not to include escape special characters
Returns:
A list of parsed and properly escaped arguments.

_escapeQuotesAndBackslashes

protected static String _escapeQuotesAndBackslashes(String s)
Inserts backslashes before any occurrences of a backslash or quote in the given string. Also converts any special characters appropriately.