Package org.apache.commons.exec.util
Class StringUtils
- java.lang.Object
-
- org.apache.commons.exec.util.StringUtils
-
public class StringUtils extends java.lang.Object
Supplement of commons-lang, the stringSubstitution() was in a simpler implementation available in an older commons-lang implementation. This class is not part of the public API and could change without warning.- Version:
- $Id: StringUtils.java 1636204 2014-11-02 22:30:31Z ggregory $
-
-
Field Summary
Fields Modifier and Type Field Description private static char
BACKSLASH_CHAR
private static java.lang.String
DOUBLE_QUOTE
private static java.lang.String
SINGLE_QUOTE
private static char
SLASH_CHAR
-
Constructor Summary
Constructors Constructor Description StringUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
fixFileSeparatorChar(java.lang.String arg)
Fixes the file separator char for the target platform using the following replacement.static boolean
isQuoted(java.lang.String argument)
Determines if this is a quoted argument - either single or double quoted.static java.lang.String
quoteArgument(java.lang.String argument)
Put quotes around the given String if necessary.static java.lang.String[]
split(java.lang.String input, java.lang.String splitChar)
Split a string into an array of strings based on a separator.static java.lang.StringBuffer
stringSubstitution(java.lang.String argStr, java.util.Map<? super java.lang.String,?> vars, boolean isLenient)
Perform a series of substitutions.static java.lang.String
toString(java.lang.String[] strings, java.lang.String separator)
Concatenates an array of string using a separator.
-
-
-
Field Detail
-
SINGLE_QUOTE
private static final java.lang.String SINGLE_QUOTE
- See Also:
- Constant Field Values
-
DOUBLE_QUOTE
private static final java.lang.String DOUBLE_QUOTE
- See Also:
- Constant Field Values
-
SLASH_CHAR
private static final char SLASH_CHAR
- See Also:
- Constant Field Values
-
BACKSLASH_CHAR
private static final char BACKSLASH_CHAR
- See Also:
- Constant Field Values
-
-
Method Detail
-
stringSubstitution
public static java.lang.StringBuffer stringSubstitution(java.lang.String argStr, java.util.Map<? super java.lang.String,?> vars, boolean isLenient)
Perform a series of substitutions.The substitutions are performed by replacing ${variable} in the target string with the value of provided by the key "variable" in the provided hash table.
A key consists of the following characters:
- letter
- digit
- dot character
- hyphen character
- plus character
- underscore character
- Parameters:
argStr
- the argument string to be processedvars
- name/value pairs used for substitutionisLenient
- ignore a key not found in vars or throw a RuntimeException?- Returns:
- String target string with replacements.
-
split
public static java.lang.String[] split(java.lang.String input, java.lang.String splitChar)
Split a string into an array of strings based on a separator.- Parameters:
input
- what to splitsplitChar
- what to split on- Returns:
- the array of strings
-
fixFileSeparatorChar
public static java.lang.String fixFileSeparatorChar(java.lang.String arg)
Fixes the file separator char for the target platform using the following replacement.- '/' → File.separatorChar
- '\\' → File.separatorChar
- Parameters:
arg
- the argument to fix- Returns:
- the transformed argument
-
toString
public static java.lang.String toString(java.lang.String[] strings, java.lang.String separator)
Concatenates an array of string using a separator.- Parameters:
strings
- the strings to concatenateseparator
- the separator between two strings- Returns:
- the concatenated strings
-
quoteArgument
public static java.lang.String quoteArgument(java.lang.String argument)
Put quotes around the given String if necessary.If the argument doesn't include spaces or quotes, return it as is. If it contains double quotes, use single quotes - else surround the argument by double quotes.
- Parameters:
argument
- the argument to be quoted- Returns:
- the quoted argument
- Throws:
java.lang.IllegalArgumentException
- If argument contains both types of quotes
-
isQuoted
public static boolean isQuoted(java.lang.String argument)
Determines if this is a quoted argument - either single or double quoted.- Parameters:
argument
- the argument to check- Returns:
- true when the argument is quoted
-
-