Class StringUtils

java.lang.Object
org.forgerock.maven.plugins.xcite.utils.StringUtils

public final class StringUtils extends Object
Utility methods for handling strings.
  • Method Details

    • asString

      public static String asString(ArrayList<String> lines)
      Return lines joined with line separators as a String.
      Parameters:
      lines - Lines to join with line separators.
      Returns:
      Lines joined with line separators as a String.
    • escapeXml

      public static ArrayList<String> escapeXml(ArrayList<String> strings)
      Escape an array of quote strings, for safe inclusion in an XML document.

      This method deals only with &amp;, &lt;, &gt;, &quot;, &apos;.

      Parameters:
      strings - The array of strings to escape.
      Returns:
      The array of escaped strings.
    • escapeXml

      public static String escapeXml(String string)
      Escape a quote string to be safely included in an XML document.

      This method deals only with &amp;, &lt;, &gt;, &quot;, &apos;.

      Parameters:
      string - The string to escape.
      Returns:
      The escaped string.
    • extractQuote

      public static ArrayList<String> extractQuote(ArrayList<String> text, String start, String end)
      Extract a single quote from an array of strings.

      The quote is surrounded by a string marking the start of the quote, and a string marking the end of the quote.

      If the start marker is null or empty, then this method assumes the entire input text is the quote.

      If the start marker exists but the end marker is null or empty, then this method assumes everything after the start marker is the quote.

      This method does not allow a null or empty end marker. To quote from the start marker to the end of the text, use an end marker that does not show up in the text.

      Unless the start marker and end marker are found on the same line, this method assumes the start marker and end marker lines are separate from the quote. In other words, for this case the method ignores substrings following the start marker on the same line and substrings preceding the end marker on the same line, unless both markers are on the same line.

      Parameters:
      text - Strings possibly containing a quote.
      start - String marking start of quote.
      end - String marking end of quote.
      Returns:
      Array of strings containing the quote.
      Throws:
      IllegalArgumentException - End marker was null or empty.
    • extractQuote

      public static ArrayList<String> extractQuote(ArrayList<String> text, String marker)
      Extract a single quote from an array of strings.

      The quote is surrounded by a single string that marks both the start of the quote and the end of the quote.

      If the marker is null or empty, then the entire input text is the quote.

      If the start marker exists but end marker is null or empty, then this method assumes everything after the start marker is the quote.

      Unless the markers are found on the same line, this method assumes the markers lines are separate from the quote. In other words, for this case the method ignores substrings following the initial marker on the same line and substrings preceding the final marker on the same line, unless both markers are on the same line.

      Parameters:
      text - The array of strings supposed to contain a quote.
      marker - The string marking the start and end of the quote.
      Returns:
      The array of strings containing the quote.
    • indent

      public static ArrayList<String> indent(ArrayList<String> text, String indent)
      Indent an array of strings.
      Parameters:
      text - Array of strings to indent.
      indent - The indentation string, usually a series of spaces.
      Returns:
      The indented array of strings.
    • outdent

      public static ArrayList<String> outdent(ArrayList<String> indented)
      Outdent an array of strings, removing an equal number of leftmost spaces from each string until at least one string starts with a non-space character.

      Tab width (or height) depends and is subject to debate, so throw an exception if the initial whitespace includes a tab.

      Parameters:
      indented - Array of strings with leftmost spaces.
      Returns:
      Strings with leftmost spaces removed.
      Throws:
      IllegalArgumentException - Initial whitespace included a tab.
    • removeEmptySpace

      public static String removeEmptySpace(String string)
      Return an empty string if the string is only whitespace. Otherwise return the original string.
      Parameters:
      string - The input string.
      Returns:
      An empty string if the input string is only whitespace, otherwise the original string.