ccs.utils
Class CommandlineParser

java.lang.Object
  extended by ccs.utils.CommandlineParser

public class CommandlineParser
extends java.lang.Object

A parser which converts a command-line string into a sequence of parameters, suitable for passing to Runtime.exec. It has three parse rules:

  1. Anything inside double quotes "like this" is part of a single parameter. The quote marks are also part of the parameter (they are not stripped). This allows e.g. Windows filenames which have spaces in them to be parsed correctly if quoted, as Windows specifies.
  2. Any whitespace not in "double quotes" is a parameter separator. Doubled spaces have no effect; empty parameters are not permitted.
  3. any instance of the character '@' is replaced with a supplied, fixed String. This allows, for example, a variable filename to be embedded in the commandline in whatever way is required. The '@' character is escaped by repeating it: "@@" becomes "@" and not the fixed string twice.


    Method Summary
    static java.lang.String[] parse(java.lang.String parseme, java.lang.String toSubst, boolean shouldAppend)
              Parses the supplied string.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Method Detail

    parse

    public static java.lang.String[] parse(java.lang.String parseme,
                                           java.lang.String toSubst,
                                           boolean shouldAppend)
    Parses the supplied string.

    Parameters:
    parseme - The string to parse.
    toSubst - The fixed string to substitute for '@' characters within parseme.
    shouldAppend - If true and no instance of '@' occurs, the fixed string is appended as an extra parameter.
    Returns:
    the array of parameters.