Class StringUtil

java.lang.Object
org.eclipse.birt.report.model.api.util.StringUtil

public class StringUtil extends Object
Collection of string utilities.
  • Field Details

  • Constructor Details

    • StringUtil

      public StringUtil()
  • Method Details

    • trimString

      public static String trimString(String value)
      Trim a string. Removes leading and trailing blanks. If the resulting string is empty, normalizes the string to an null string.
      Parameters:
      value - the string to trim
      Returns:
      the trimmed string, or null if the string is empty
    • toRgbText

      public static String toRgbText(int rgb)
      Convert an integer to an HTML RGB value. The result is of the form #hhhhhh. The input rgb integer value will be clipped into the range 0 ~ 0xFFFFFF
      Parameters:
      rgb - the integer RGB value
      Returns:
      the value as an HTML RGB string
    • isValidLocale

      public static boolean isValidLocale(String locale)
      Check if the locale string is a valid locale format, with the language, country and variant separated by underbars.

      The language argument is a valid ISO Language Code. . These codes are the lower-case, two-letter codes.

      The country argument is a valid ISO Country Code. These codes are the upper-case, two-letter codes.

      If the language is missing, the string should begin with an underbar. (Can't have a locale with just a variant -- the variant must accompany a valid language or country code). Examples: "en", "de_DE", "_GB", "en_US_WIN", "de__POSIX", "fr__MAC"

      Parameters:
      locale - string representing a locale
      Returns:
      true if the locale is a valid locale, false if the locale is not valid.
    • isBlank

      public static boolean isBlank(String str)
      Reports if a string is blank. A string is considered blank either if it is null, is an empty string, of consists entirely of white space.

      For example,

      • null, "" and " " are blank strings
      Parameters:
      str - the string to check
      Returns:
      true if the string is blank, false otherwise.
    • isEmpty

      public static boolean isEmpty(String value)
      Reports if a string is empty. A string is considered empty either if it is null, is an empty string.

      For example,

      • Both null and "" are empty strings
      • " " is not empty string.
      Parameters:
      value - the string to check
      Returns:
      true if the string is empty, false otherwise.
    • isEqual

      public static boolean isEqual(String str1, String str2)
      Returns if the two string are null or equal. The String.equals(String)is used to compare two strings.
      Parameters:
      str1 - the string to compare
      str2 - the string to compare
      Returns:
      true, if the two string are null, or the two string are equal with case sensitive.
    • isEqualIgnoreCase

      public static boolean isEqualIgnoreCase(String str1, String str2)
      Returns if the two string are null or equal. The String.equalsIgnoreCase(String)is used to compare two strings.
      Parameters:
      str1 - the string to compare
      str2 - the string to compare
      Returns:
      true, if the two string are null, or the two string are equal with case sensitive.
    • doubleToString

      public static String doubleToString(double d, int fNumber)
      Converts the double value to locale-independent string representation. This method works like Double.toString( double ), and can also handle very large number like 1.234567890E16 to "12345678900000000".
      Parameters:
      d - the double value to convert
      fNumber - the positive maximum fractional number
      Returns:
      the locale-independent string representation.
    • doubleToString

      public static String doubleToString(double d, int fNumber, com.ibm.icu.util.ULocale locale)
      Converts the double value to locale-dependent string representation.
      Parameters:
      d - the double value to convert
      fNumber - the positive maximum fractional number
      locale -
      Returns:
      the locale-dependent string representation.
    • parse

      public static DimensionValue parse(String value) throws PropertyValueException
      Parses a dimension string in locale-independent way. The input string must match the following:
      • null
      • [1-9][0-9]*[.[0-9]*[ ]*[in|cm|mm|pt|pc|em|ex|px|%]]
      Parameters:
      value - the dimension string to parse
      Returns:
      a dimension object representing the dimension string.
      Throws:
      PropertyValueException - if the string is not valid
    • parseInput

      public static DimensionValue parseInput(String value, com.ibm.icu.util.ULocale locale) throws PropertyValueException
      Parses a dimension string in locale-dependent way. The input can be in localized value. The measure part use the decimal separator from the locale. e,g. "123,456.78" for English ; "123.456,78" for German.

      The string must match the following:

      • null
      • [1-9][0-9]*[.[0-9]*[ ]*[u]], u is the one of the allowed units

      Parameters:
      value - the string to parse
      locale - the locale where the input string resides
      Returns:
      a dimension object
      Throws:
      PropertyValueException - if the string is not valid
    • extractFileName

      public static String extractFileName(String filePathName)
      Extract file name (without path and suffix) from file name with path and suffix.

      For example:

      • "c:\home\abc.xml" => "abc"
      • "c:\home\abc" => "abc"
      • "/home/user/abc.xml" => "abc"
      • "/home/user/abc" => "abc"
      Parameters:
      filePathName - the file name with path and suffix
      Returns:
      the file name without path and suffix
    • extractFileNameWithSuffix

      public static String extractFileNameWithSuffix(String filePathName)
      Extract file name (without path but with suffix) from file name with path and suffix.

      For example:

      • "c:\home\abc.xml" => "abc.xml"
      • "c:\home\abc" => "abc"
      • "/home/user/abc.xml" => "abc.xml"
      • "/home/user/abc" => "abc"
      Parameters:
      filePathName - the file name with path and suffix
      Returns:
      the file name without path but with suffix
    • extractNamespace

      public static String extractNamespace(String qualifiedName)
      Extracts the libaray namespace from the given qualified reference value.

      For example,

      • "LibA" is extracted from "LibA.style1"
      • null is returned from "style1"
      Parameters:
      qualifiedName - the qualified reference value
      Returns:
      the library namespace
    • extractName

      public static String extractName(String qualifiedName)
      Extracts the name from the given qualified reference value.

      For example,

      • "style1" is extracted from "LibA.style1"
      • "style1" is returned from "style1"
      Parameters:
      qualifiedName - the qualified reference value
      Returns:
      the name
    • buildQualifiedReference

      public static String buildQualifiedReference(String namespace, String value)
      Builds the qualified reference value.

      For example,

      • ("LibA", "style1") => "LibA.style1"
      • (" ", "style1) => "style1"
      Parameters:
      namespace - the library namespace to indicate which library the reference is using.
      value - the actual reference value
      Returns:
      the qualified reference value
    • trimQuotes

      public static String trimQuotes(String value)
      Trims the quotes.

      For example,

      • ("a.b") => a.b
      • ("a.b) => "a.b
      • (a.b") => a.b"
      Parameters:
      value - the string may have quotes
      Returns:
      the string without quotes