public final class ParametersListUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static Function<java.util.List<java.lang.String>,java.lang.String> |
COLON_LINE_JOINER |
static Function<java.lang.String,java.util.List<java.lang.String>> |
COLON_LINE_PARSER |
static Function<java.util.List<java.lang.String>,java.lang.String> |
DEFAULT_LINE_JOINER |
static Function<java.lang.String,java.util.List<java.lang.String>> |
DEFAULT_LINE_PARSER |
Constructor and Description |
---|
ParametersListUtil() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
escape(java.lang.CharSequence argument)
Escapes a single argument.
|
static java.lang.String |
join(java.util.List<? extends java.lang.CharSequence> parameters)
Joins list of parameters into single string, which may be then parsed back into list by
parseToArray(String) . |
static <T extends java.lang.CharSequence> |
join(java.util.List<? extends T> parameters,
Function<? super T,? extends java.lang.CharSequence> escapeFunction) |
static java.lang.String |
join(java.lang.String... parameters) |
static java.util.List<java.lang.String> |
parse(java.lang.String parameterString)
Splits single parameter string (as created by
join(List) ) into list of parameters. |
static java.util.List<java.lang.String> |
parse(java.lang.String parameterString,
boolean keepQuotes) |
static java.util.List<java.lang.String> |
parse(java.lang.String parameterString,
boolean keepQuotes,
boolean supportSingleQuotes) |
static java.util.List<java.lang.String> |
parse(java.lang.String parameterString,
boolean keepQuotes,
boolean supportSingleQuotes,
boolean keepEmptyParameters) |
static java.lang.String [] |
parseToArray(java.lang.String string) |
public static final Function<java.lang.String,java.util.List<java.lang.String>> DEFAULT_LINE_PARSER
public static final Function<java.util.List<java.lang.String>,java.lang.String> DEFAULT_LINE_JOINER
public static final Function<java.lang.String,java.util.List<java.lang.String>> COLON_LINE_PARSER
public static final Function<java.util.List<java.lang.String>,java.lang.String> COLON_LINE_JOINER
public static java.lang.String join(java.util.List<? extends java.lang.CharSequence> parameters)
Joins list of parameters into single string, which may be then parsed back into list by parseToArray(String)
.
Conversion rules:
\
);"
);Examples:
['a', 'b'] => 'a b'
['a="1 2"', 'b'] => '"a \"1 2\"" b'
parameters
- a list of parameters to join.public static <T extends java.lang.CharSequence> java.lang.String join(java.util.List<? extends T> parameters, Function<? super T,? extends java.lang.CharSequence> escapeFunction)
escapeFunction
- defines how to handle (quote/escape) special characters in each command line argumentjoin(List)
public static java.lang.String join(java.lang.String... parameters)
public static java.lang.String [] parseToArray(java.lang.String string)
parse(String)
public static java.util.List<java.lang.String> parse(java.lang.String parameterString)
Splits single parameter string (as created by join(List)
) into list of parameters.
Conversion rules:
"a b"
) are kept as single one;\"
) are un-escaped.parse(String, boolean, boolean)
Examples:
' a b ' => ['a', 'b']
'a="1 2" b' => ['a=1 2', 'b']
'a " " b' => ['a', ' ', 'b']
'"a \"1 2\"" b' => ['a="1 2"', 'b']
parameterString
- parameter string to split.public static java.util.List<java.lang.String> parse(java.lang.String parameterString, boolean keepQuotes)
public static java.util.List<java.lang.String> parse(java.lang.String parameterString, boolean keepQuotes, boolean supportSingleQuotes)
public static java.util.List<java.lang.String> parse(java.lang.String parameterString, boolean keepQuotes, boolean supportSingleQuotes, boolean keepEmptyParameters)
public static java.lang.String escape(java.lang.CharSequence argument)
parse(java.lang.String)
so that the following invariants are held:
assert parse(escape(arg)).size() == 1; assert parse(escape(arg)).get(0).equals(arg);