Class StringUtil


  • public final class StringUtil
    extends Object
    A minimal String utility class. Designed for internal jsoup use only.
    • Constructor Detail

      • StringUtil

        public StringUtil()
    • Method Detail

      • join

        public static String join​(Collection strings,
                                  String sep)
        Join a collection of strings by a separator
        Parameters:
        strings - collection of string objects
        sep - string to place between strings
        Returns:
        joined string
      • join

        public static String join​(Iterator strings,
                                  String sep)
        Join a collection of strings by a separator
        Parameters:
        strings - iterator of string objects
        sep - string to place between strings
        Returns:
        joined string
      • padding

        public static String padding​(int width)
        Returns space padding
        Parameters:
        width - amount of padding desired
        Returns:
        string of spaces * width
      • isBlank

        public static boolean isBlank​(String string)
        Tests if a string is blank: null, empty, or only whitespace (" ", \r\n, \t, etc)
        Parameters:
        string - string to test
        Returns:
        if string is blank
      • isNumeric

        public static boolean isNumeric​(String string)
        Tests if a string is numeric, i.e. contains only digit characters
        Parameters:
        string - string to test
        Returns:
        true if only digit chars, false if empty or null or contains non-digit chars
      • isWhitespace

        public static boolean isWhitespace​(int c)
        Tests if a code point is "whitespace" as defined in the HTML spec.
        Parameters:
        c - code point to test
        Returns:
        true if code point is whitespace, false otherwise
      • normaliseWhitespace

        public static String normaliseWhitespace​(String string)
        Normalise the whitespace within this string; multiple spaces collapse to a single, and all whitespace characters (e.g. newline, tab) convert to a simple space
        Parameters:
        string - content to normalise
        Returns:
        normalised string
      • appendNormalisedWhitespace

        public static void appendNormalisedWhitespace​(StringBuilder accum,
                                                      String string,
                                                      boolean stripLeading)
        After normalizing the whitespace within a string, appends it to a string builder.
        Parameters:
        accum - builder to append to
        string - string to normalize whitespace within
        stripLeading - set to true if you wish to remove any leading whitespace
      • in

        public static boolean in​(String needle,
                                 String... haystack)
      • inSorted

        public static boolean inSorted​(String needle,
                                       String[] haystack)
      • resolve

        public static URL resolve​(URL base,
                                  String relUrl)
                           throws MalformedURLException
        Create a new absolute URL, from a provided existing absolute URL and a relative URL component.
        Parameters:
        base - the existing absolute base URL
        relUrl - the relative URL to resolve. (If it's already absolute, it will be returned)
        Returns:
        the resolved absolute URL
        Throws:
        MalformedURLException - if an error occurred generating the URL
      • resolve

        public static String resolve​(String baseUrl,
                                     String relUrl)
        Create a new absolute URL, from a provided existing absolute URL and a relative URL component.
        Parameters:
        baseUrl - the existing absolute base URL
        relUrl - the relative URL to resolve. (If it's already absolute, it will be returned)
        Returns:
        an absolute URL if one was able to be generated, or the empty string if not