org.apache.tools.ant.utilClass StringUtils
- java.lang.Object
 
- org.apache.tools.ant.util.StringUtils
 
public final class StringUtils extends java.lang.ObjectA set of helper methods related to string manipulation.
Field Summary
Fields Modifier and Type Field and Description static java.lang.StringLINE_SEPthe line separator for this OS
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description static booleanendsWith(java.lang.StringBuffer buffer, java.lang.String suffix)Checks that a string buffer ends up with a given string.static java.lang.StringgetStackTrace(java.lang.Throwable t)Convenient method to retrieve the full stacktrace from a given exception.static java.util.Vector<java.lang.String>lineSplit(java.lang.String data)Splits up a string into a list of lines.static longparseHumanSizes(java.lang.String humanSize)Takes a human readable size representation eg 10K a long value.static java.lang.StringremovePrefix(java.lang.String string, java.lang.String prefix)Removes the prefix from a given string, if the string contains that prefix.static java.lang.StringremoveSuffix(java.lang.String string, java.lang.String suffix)Removes the suffix from a given string, if the string contains that suffix.static java.lang.Stringreplace(java.lang.String data, java.lang.String from, java.lang.String to)Deprecated.UseString.replace(CharSequence, CharSequence)now.static java.lang.StringresolveBackSlash(java.lang.String input)xml does not do "c" like interpretation of strings.static java.util.Vector<java.lang.String>split(java.lang.String data, int ch)Splits up a string where elements are separated by a specific character and return all elements.
Method Detail
lineSplit
public static java.util.Vector<java.lang.String> lineSplit(java.lang.String data)Splits up a string into a list of lines. It is equivalent to split(data, '\n').
- Parameters:
 data- the string to split up into lines.- Returns:
 - the list of lines available in the string.
 
split
public static java.util.Vector<java.lang.String> split(java.lang.String data, int ch)Splits up a string where elements are separated by a specific character and return all elements.
- Parameters:
 data- the string to split up.ch- the separator character.- Returns:
 - the list of elements.
 
replace
@Deprecated public static java.lang.String replace(java.lang.String data, java.lang.String from, java.lang.String to)Deprecated. UseString.replace(CharSequence, CharSequence)now.Replace occurrences into a string.
- Parameters:
 data- the string to replace occurrences intofrom- the occurrence to replace.to- the occurrence to be used as a replacement.- Returns:
 - the new string with replaced occurrences.
 
getStackTrace
public static java.lang.String getStackTrace(java.lang.Throwable t)Convenient method to retrieve the full stacktrace from a given exception.
- Parameters:
 t- the exception to get the stacktrace from.- Returns:
 - the stacktrace from the given exception.
 
endsWith
public static boolean endsWith(java.lang.StringBuffer buffer, java.lang.String suffix)Checks that a string buffer ends up with a given string. It may sound trivial with the existing JDK API but the various implementation among JDKs can make those methods extremely resource intensive and perform poorly due to massive memory allocation and copying. See
- Parameters:
 buffer- the buffer to perform the check onsuffix- the suffix- Returns:
 trueif the character sequence represented by the argument is a suffix of the character sequence represented by the StringBuffer object;falseotherwise. Note that the result will betrueif the argument is the empty string.
resolveBackSlash
public static java.lang.String resolveBackSlash(java.lang.String input)xml does not do "c" like interpretation of strings. i.e. \n\r\t etc. this method processes \n, \r, \t, \f, \\ also subs \s -> " \n\r\t\f" a trailing '\' will be ignored
- Parameters:
 input- raw string with possible embedded '\'s- Returns:
 - converted string
 - Since:
 - Ant 1.7
 
parseHumanSizes
public static long parseHumanSizes(java.lang.String humanSize) throws java.lang.ExceptionTakes a human readable size representation eg 10K a long value. Doesn't support 1.1K or other rational values.
- Parameters:
 humanSize- the amount as a human readable string.- Returns:
 - a long value representation
 - Throws:
 java.lang.Exception- if there is a problem.- Since:
 - Ant 1.7
 
removeSuffix
public static java.lang.String removeSuffix(java.lang.String string, java.lang.String suffix)Removes the suffix from a given string, if the string contains that suffix.
- Parameters:
 string- String for checksuffix- Suffix to remove- Returns:
 - the string with the suffix
 
removePrefix
public static java.lang.String removePrefix(java.lang.String string, java.lang.String prefix)Removes the prefix from a given string, if the string contains that prefix.
- Parameters:
 string- String for checkprefix- Prefix to remove- Returns:
 - the string with the prefix