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
ConstructorsModifierConstructorDescriptionprivate
StringUtils
instances should NOT be constructed in standard programming. -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Checks if a String isnull
or empty.static String
Remove all duplicate whitespace characters and line terminators are replaced with a single space.static String
Repeat a Stringn
times to form a new string.static String[]
private static String[]
Splits the provided text into a array, based on a given separator.static String
unifyLineSeparators
(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()StringUtils
instances 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 isnull
or empty.Note: In releases prior 3.5.0, this method trimmed the input string such that it worked the same as
invalid reference
#isBlank(String)
true
for strings containing only whitespace characters.- Parameters:
str
- the String to check- Returns:
true
if 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
null
separator 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
StringTokenizer
does).- 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
n
times to form a new string.- Parameters:
str
- String to repeatrepeat
- number of times to repeat str- Returns:
- String with repeated String
- Throws:
NegativeArraySizeException
- ifrepeat < 0
NullPointerException
- 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
-