Class StringUtils

java.lang.Object
org.codehaus.plexus.util.xml.StringUtils

class StringUtils extends Object

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 Details

    • StringUtils

      private StringUtils()

      StringUtils instances should NOT be constructed in standard programming. Instead, the class should be used as StringUtils.trim(" foo ");.

      This constructor is public to permit tools that require a JavaBean manager to operate.

  • Method Details

    • isEmpty

      public static boolean isEmpty(String str)
      Checks if a String is null or 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 returns true for strings containing only whitespace characters.

      Parameters:
      str - the String to check
      Returns:
      true if the String is null, or length zero
    • split

      public static String[] split(String text, String separator)
      Parameters:
      text - The string to parse.
      separator - Characters used as the delimiters. If null, splits on whitespace.
      Returns:
      an array of parsed Strings
    • split

      private static String[] split(String str, 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 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. If null, 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 String repeat(String str, int repeat)

      Repeat a String n times to form a new string.

      Parameters:
      str - String to repeat
      repeat - number of times to repeat str
      Returns:
      String with repeated String
      Throws:
      NegativeArraySizeException - if repeat < 0
      NullPointerException - if str is null
    • removeDuplicateWhitespace

      public static String removeDuplicateWhitespace(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 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.
      Parameters:
      s - a not null String
      ls - 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