Class StringUtils
- java.lang.Object
-
- org.codehaus.plexus.util.xml.StringUtils
-
class StringUtils extends java.lang.ObjectCommon
Stringmanipulation routines, extracted from Plexus Utils and trimmed down for Plexus Xml.Originally from Turbine and the GenerationJavaCore library.
- Since:
- 1.0
-
-
Constructor Summary
Constructors Modifier Constructor Description privateStringUtils()StringUtilsinstances should NOT be constructed in standard programming.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanisEmpty(java.lang.String str)Checks if a String isnullor empty.static java.lang.StringremoveDuplicateWhitespace(java.lang.String s)Remove all duplicate whitespace characters and line terminators are replaced with a single space.static java.lang.Stringrepeat(java.lang.String str, int repeat)Repeat a Stringntimes to form a new string.static java.lang.String[]split(java.lang.String text, java.lang.String separator)private static java.lang.String[]split(java.lang.String str, java.lang.String separator, int max)Splits the provided text into a array, based on a given separator.static java.lang.StringunifyLineSeparators(java.lang.String s, java.lang.String ls)Parses the given String and replaces all occurrences of '\n', '\r' and '\r\n' with the system line separator.
-
-
-
Method Detail
-
isEmpty
public static boolean isEmpty(java.lang.String str)
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
#isBlank(String). Since release 3.5.0 it no longer returnstruefor strings containing only whitespace characters.- Parameters:
str- the String to check- Returns:
trueif the String isnull, or length zero
-
split
public static java.lang.String[] split(java.lang.String text, java.lang.String separator)- Parameters:
text- The string to parse.separator- Characters used as the delimiters. Ifnull, splits on whitespace.- Returns:
- an array of parsed Strings
-
split
private static java.lang.String[] split(java.lang.String str, java.lang.String separator, int max)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
public static java.lang.String repeat(java.lang.String str, int 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:
java.lang.NegativeArraySizeException- ifrepeat < 0java.lang.NullPointerException- if str isnull
-
removeDuplicateWhitespace
public static java.lang.String removeDuplicateWhitespace(java.lang.String s)
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
public static java.lang.String unifyLineSeparators(java.lang.String s, java.lang.String ls)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:
java.lang.IllegalArgumentException- if ls is not '\n', '\r' and '\r\n' characters.- Since:
- 1.5.7
-
-