Class StringUtils
Common String manipulation routines, extracted from Plexus Utils and trimmed down for Plexus Xml.
Originally from Turbine and the GenerationJavaCore library.
- Since:
- 1.0
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateStringUtilsinstances should NOT be constructed in standard programming. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanChecks if a String isnullor empty.static StringRemove all duplicate whitespace characters and line terminators are replaced with a single space.static StringRepeat a Stringntimes to form a new string.static String[]private static String[]Splits the provided text into a array, based on a given separator.static StringunifyLineSeparators(String s, String ls) Parses the given String and replaces all occurrences of '\n', '\r' and '\r\n' with the system line separator.
-
Constructor Details
-
StringUtils
private StringUtils()StringUtilsinstances should NOT be constructed in standard programming. Instead, the class should be used asStringUtils.trim(" foo ");.This constructor is public to permit tools that require a JavaBean manager to operate.
-
-
Method Details
-
isEmpty
Checks if a String isnullor empty.Note: In releases prior 3.5.0, this method trimmed the input string such that it worked the same as
. Since release 3.5.0 it no longer returnsinvalid reference
#isBlank(String)truefor strings containing only whitespace characters.- Parameters:
str- the String to check- Returns:
trueif the String isnull, or length zero
-
split
- Parameters:
text- The string to parse.separator- Characters used as the delimiters. Ifnull, splits on whitespace.- Returns:
- an array of parsed Strings
-
split
Splits the provided text into a array, based on a given separator.
The separator is not included in the returned String array. The maximum number of splits to perform can be controlled. A
nullseparator will cause parsing to be on whitespace.This is useful for quickly splitting a String directly into an array of tokens, instead of an enumeration of tokens (as
StringTokenizerdoes).- Parameters:
str- The string to parse.separator- Characters used as the delimiters. Ifnull, splits on whitespace.max- The maximum number of elements to include in the array. A zero or negative value implies no limit.- Returns:
- an array of parsed Strings
-
repeat
Repeat a String
ntimes to form a new string.- Parameters:
str- String to repeatrepeat- number of times to repeat str- Returns:
- String with repeated String
- Throws:
NegativeArraySizeException- ifrepeat < 0NullPointerException- if str isnull
-
removeDuplicateWhitespace
Remove all duplicate whitespace characters and line terminators are replaced with a single space.- Parameters:
s- a not null String- Returns:
- a string with unique whitespace.
- Since:
- 1.5.7
-
unifyLineSeparators
Parses the given String and replaces all occurrences of '\n', '\r' and '\r\n' with the system line separator.- Parameters:
s- a not null Stringls- the wanted line separator ("\n" on UNIX), if null using the System line separator.- Returns:
- a String that contains only System line separators.
- Throws:
IllegalArgumentException- if ls is not '\n', '\r' and '\r\n' characters.- Since:
- 1.5.7
-