org.apache.tools.ant.util

Class StringUtils

public final class StringUtils extends Object

A set of helper methods related to string manipulation.
Field Summary
static StringLINE_SEP
the line separator for this OS
Method Summary
static booleanendsWith(StringBuffer buffer, String suffix)
Checks that a string buffer ends up with a given string.
static StringgetStackTrace(Throwable t)
Convenient method to retrieve the full stacktrace from a given exception.
static VectorlineSplit(String data)
Splits up a string into a list of lines.
static longparseHumanSizes(String humanSize)
Takes a human readable size representation eg 10K a long value.
static StringremovePrefix(String string, String prefix)
Removes the prefix from a given string, if the string contains that prefix.
static StringremoveSuffix(String string, String suffix)
Removes the suffix from a given string, if the string contains that suffix.
static Stringreplace(String data, String from, String to)
Replace occurrences into a string.
static StringresolveBackSlash(String input)
xml does not do "c" like interpretation of strings. i.e.
static Vectorsplit(String data, int ch)
Splits up a string where elements are separated by a specific character and return all elements.

Field Detail

LINE_SEP

public static final String LINE_SEP
the line separator for this OS

Method Detail

endsWith

public static boolean endsWith(StringBuffer buffer, 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 on suffix the suffix

Returns: true if the character sequence represented by the argument is a suffix of the character sequence represented by the StringBuffer object; false otherwise. Note that the result will be true if the argument is the empty string.

getStackTrace

public static String getStackTrace(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.

lineSplit

public static Vector lineSplit(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.

parseHumanSizes

public static long parseHumanSizes(String humanSize)
Takes 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: Exception if there is a problem.

Since: Ant 1.7

removePrefix

public static String removePrefix(String string, String prefix)
Removes the prefix from a given string, if the string contains that prefix.

Parameters: string String for check prefix Prefix to remove

Returns: the string with the prefix

removeSuffix

public static String removeSuffix(String string, String suffix)
Removes the suffix from a given string, if the string contains that suffix.

Parameters: string String for check suffix Suffix to remove

Returns: the string with the suffix

replace

public static String replace(String data, String from, String to)
Replace occurrences into a string.

Parameters: data the string to replace occurrences into from the occurrence to replace. to the occurrence to be used as a replacement.

Returns: the new string with replaced occurrences.

resolveBackSlash

public static String resolveBackSlash(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

split

public static Vector split(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.