JavaScript is disabled on your browser.
Skip navigation links
  • Summary:
  • Nested |
  • Field |
  • Constr |
  • Method
  • Detail:
  • Field |
  • Constr |
  • Method
org.htmlunit.util

Class StringUtils



  • public final class StringUtils
    extends Object 
    String utilities class for utility functions not covered by third party libraries.
    Author:
    Daniel Gredler, Ahmed Ashour, Martin Tamme, Ronald Brill
    • Method Detail

      • isEmptyString

        public static boolean isEmptyString(CharSequence s)
        Returns true if the param is not null and empty. This is different from StringUtils.isEmpty(CharSequence) because this returns false if the provided string is null.
        Parameters:
        s - the string to check
        Returns:
        true if the param is not null and empty
      • isEmptyOrNull

        public static boolean isEmptyOrNull(CharSequence s)
        Returns true if the param is null or empty.
        Parameters:
        s - the string to check
        Returns:
        true if the param is null or empty
      • defaultIfEmptyOrNull

        public static <T extends CharSequence> T defaultIfEmptyOrNull(T s,
         T defaultString)
        Returns either the passed in CharSequence, or if the CharSequence is empty or null, the default value.
        Type Parameters:
        T - the kind of CharSequence
        Parameters:
        s - the CharSequence to check
        defaultString - the default to return if the input is empty or null
        Returns:
        the passed in CharSequence, or the defaultString
      • isBlank

        public static boolean isBlank(CharSequence s)
        Tests if a CharSequence is null, empty, or contains only whitespace.
        Parameters:
        s - the CharSequence to check
        Returns:
        true if a CharSequence is null, empty, or contains only whitespace
      • isNotBlank

        public static boolean isNotBlank(CharSequence s)
        Tests if a CharSequence is NOT null, empty, or contains only whitespace.
        Parameters:
        s - the CharSequence to check
        Returns:
        false if a CharSequence is null, empty, or contains only whitespace
      • equalsChar

        public static boolean equalsChar(char expected,
         CharSequence s)
        Parameters:
        expected - the char that we expect
        s - the string to check
        Returns:
        true if the provided string has only one char and this matches the expectation
      • startsWithIgnoreCase

        public static boolean startsWithIgnoreCase(String s,
         String expectedStart)
        Tests if a CharSequence starts with a specified prefix.
        Parameters:
        s - the string to check
        expectedStart - the string that we expect at the beginning (has to be not null and not empty)
        Returns:
        true if the provided string has only one char and this matches the expectation
      • endsWithIgnoreCase

        public static boolean endsWithIgnoreCase(String s,
         String expectedEnd)
        Tests if a CharSequence ends with a specified prefix.
        Parameters:
        s - the string to check
        expectedEnd - the string that we expect at the end (has to be not null and not empty)
        Returns:
        true if the provided string has only one char and this matches the expectation
      • containsIgnoreCase

        public static boolean containsIgnoreCase(String s,
         String expected)
        Tests if a CharSequence ends with a specified prefix.
        Parameters:
        s - the string to check
        expected - the string that we expect to be a substring (has to be not null and not empty)
        Returns:
        true if the provided string has only one char and this matches the expectation
      • escapeXmlChars

        public static String escapeXmlChars(String s)
        Escapes the characters '<', '>' and '&' into their XML entity equivalents.
        Parameters:
        s - the string to escape
        Returns:
        the escaped form of the specified string
      • escapeXml

        public static String escapeXml(String text)
        Escape the string to be used as xml 1.0 content be replacing the characters '"', '&', ''', '<', and '>' into their XML entity equivalents.
        Parameters:
        text - the attribute value
        Returns:
        the escaped value
      • escapeXmlAttributeValue

        public static String escapeXmlAttributeValue(String attValue)
        Escape the string to be used as attribute value. Only <, & and " have to be escaped (see http://www.w3.org/TR/REC-xml/#d0e888).
        Parameters:
        attValue - the attribute value
        Returns:
        the escaped value
      • indexOf

        public static int indexOf(String s,
         char searchChar,
         int beginIndex,
         int endIndex)
        Returns the index within the specified string of the first occurrence of the specified search character.
        Parameters:
        s - the string to search
        searchChar - the character to search for
        beginIndex - the index at which to start the search
        endIndex - the index at which to stop the search
        Returns:
        the index of the first occurrence of the character in the string or -1
      • asColorHexadecimal

        public static Color asColorHexadecimal(String token)
        Returns a Color parsed from the given RGB in hexadecimal notation.
        Parameters:
        token - the token to parse
        Returns:
        a Color whether the token is a color RGB in hexadecimal notation; otherwise null
      • findColorRGB

        public static Color findColorRGB(String token)
        Returns a Color parsed from the given rgb notation if found inside the given string.
        Parameters:
        token - the token to parse
        Returns:
        a Color whether the token contains a color in RGB notation; otherwise null
      • findColorRGBA

        public static Color findColorRGBA(String token)
        Returns a Color parsed from the given rgb notation.
        Parameters:
        token - the token to parse
        Returns:
        a Color whether the token is a color in RGB notation; otherwise null
      • findColorHSL

        public static Color findColorHSL(String token)
        Returns a Color parsed from the given hsl notation if found inside the given string.
        Parameters:
        token - the token to parse
        Returns:
        a Color whether the token contains a color in RGB notation; otherwise null
      • formatColor

        public static String formatColor(Color color)
        Formats the specified color.
        Parameters:
        color - the color to format
        Returns:
        the specified color, formatted
      • sanitizeForAppendReplacement

        public static String sanitizeForAppendReplacement(String toSanitize)
        Sanitize a string for use in Matcher.appendReplacement. Replaces all \ with \\ and $ as \$ because they are used as control characters in appendReplacement.
        Parameters:
        toSanitize - the string to sanitize
        Returns:
        sanitized version of the given string
      • sanitizeForFileName

        public static String sanitizeForFileName(String toSanitize)
        Sanitizes a string for use as filename. Replaces ,円 /, |, :, ?, *, ", <, >, control chars by _ (underscore).
        Parameters:
        toSanitize - the string to sanitize
        Returns:
        sanitized version of the given string
      • cssCamelize

        public static String cssCamelize(String string)
        Transforms the specified string from delimiter-separated (e.g. font-size) to camel-cased (e.g. fontSize).
        Parameters:
        string - the string to camelize
        Returns:
        the transformed string
      • toRootLowerCase

        public static String toRootLowerCase(String s)
        Lowercases a string by checking and check for null first. There is no cache involved and the ROOT locale is used to convert it.
        Parameters:
        s - the string to lowercase
        Returns:
        the lowercased string
      • cssDeCamelize

        public static String cssDeCamelize(String string)
        Transforms the specified string from camel-cased (e.g. fontSize) to delimiter-separated (e.g. font-size). to camel-cased .
        Parameters:
        string - the string to decamelize
        Returns:
        the transformed string
      • toByteArray

        public static byte[] toByteArray(String content,
         Charset charset)
        Converts a string into a byte array using the specified encoding.
        Parameters:
        charset - the charset
        content - the string to convert
        Returns:
        the String as a byte[]; if the specified encoding is not supported an empty byte[] will be returned
      • splitAtJavaWhitespace

        public static String[] splitAtJavaWhitespace(String str)
        Splits the provided text into an array, using whitespace as the separator. Whitespace is defined by Character.isWhitespace(char).
        Parameters:
        str - the String to parse, may be null
        Returns:
        an array of parsed Strings, an empty array if null String input
      • splitAtBlank

        public static String[] splitAtBlank(String str)
        Splits the provided text into an array, using blank as the separator.
        Parameters:
        str - the String to parse, may be null
        Returns:
        an array of parsed Strings, an empty array if null String input
      • splitAtComma

        public static String[] splitAtComma(String str)
        Splits the provided text into an array, using blank as the separator.
        Parameters:
        str - the String to parse, may be null
        Returns:
        an array of parsed Strings, an empty array if null String input
      • splitAtCommaOrBlank

        public static String[] splitAtCommaOrBlank(String str)
        Splits the provided text into an array, using comma or blank as the separator.
        Parameters:
        str - the String to parse, may be null
        Returns:
        an array of parsed Strings, an empty array if null String input
Skip navigation links
  • Summary:
  • Nested |
  • Field |
  • Constr |
  • Method
  • Detail:
  • Field |
  • Constr |
  • Method

Copyright © 2002–2025 Gargoyle Software Inc.. All rights reserved.

AltStyle によって変換されたページ (->オリジナル) /