Class Strings

java.lang.Object
org.basex.util.Strings

public final class Strings extends Object

This class provides convenience operations for strings.

Author:
BaseX Team 2005-21, BSD License, Christian Gruen
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    ISO-8859-1 encoding string.
    static final String
    UTF16 encoding string.
    static final String
    UTF16BE encoding string.
    static final String
    UTF16 encoding string.
    static final String
    UTF16 encoding string.
    static final String
    UTF8 encoding string.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    camelCase(String string)
    Converts the given string to camel case.
    static String
    Capitalizes the first letter of a string.
    static String
    className(String string)
    Converts the given string to a Java class name.
    static String
    concat(Object... objects)
    Concatenates multiple objects.
    static boolean
    contains(String string, char ch)
    Checks if a string contains a character.
    static String
    delete(String string, char ch)
    Deletes a character from a string.
    static String[]
    Returns a string array with all supported encodings.
    static boolean
    endsWith(String string, char ch)
    Checks if a string ends with the specified character.
    static boolean
    eq(String string1, String string2)
    Compares two strings for equality.
    static boolean
    eq(String string, String... strings)
    Compares several strings for equality.
    static boolean
    eqic(String string, String... strings)
    Compares several strings for equality, ignoring the case.
    static String
    md5(String string)
    Returns an MD5 hash in lower case.
    static boolean
    no(String string)
    Checks if the specified string is "no", "false", "off" or "0".
    static String
    normEncoding(String encoding)
    Returns a unified representation of the specified encoding.
    static String
    normEncoding(String encoding, boolean utf16)
    Returns a unified representation of the specified encoding.
    static String
    sha256(String string)
    Returns an SHA256 hash in lower case.
    static String[]
    split(String string, char separator)
    Splits a string around matches of the given separator.
    static String[]
    split(String string, char separator, int limit)
    Splits a string around matches of the given separator.
    static boolean
    startsWith(String string, char ch)
    Checks if a string starts with the specified character.
    static boolean
    supported(String encoding)
    Checks if the specified encoding is supported.
    static boolean
    toBoolean(String string)
    Checks if the specified string is "yes", "true", "on" or "1".
    static int
    toInt(String string)
    Converts the specified string into an integer value.
    static long
    toLong(String string)
    Converts the specified string into an long value.
    static String
    Converts a URI to a directory path.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • toLong

      public static long toLong(String string)
      Converts the specified string into an long value. Long.MIN_VALUE is returned if the input is invalid.
      Parameters:
      string - string to be converted
      Returns:
      resulting long value
    • toInt

      public static int toInt(String string)
      Converts the specified string into an integer value. Integer.MIN_VALUE is returned if the input is invalid.
      Parameters:
      string - string to be converted
      Returns:
      resulting integer value
    • toBoolean

      public static boolean toBoolean(String string)
      Checks if the specified string is "yes", "true", "on" or "1".
      Parameters:
      string - string to be checked
      Returns:
      result of check
    • eq

      public static boolean eq(String string1, String string2)
      Compares two strings for equality. The arguments may be null.
      Parameters:
      string1 - first string
      string2 - strings to be compared
      Returns:
      true if one test is successful
    • eq

      public static boolean eq(String string, String... strings)
      Compares several strings for equality. The arguments may be null.
      Parameters:
      string - first string
      strings - strings to be compared
      Returns:
      true if one test is successful
    • eqic

      public static boolean eqic(String string, String... strings)
      Compares several strings for equality, ignoring the case.
      Parameters:
      string - first string
      strings - strings to be compared
      Returns:
      true if one test is successful
    • split

      public static String[] split(String string, char separator)
      Splits a string around matches of the given separator.
      Parameters:
      string - string to be split
      separator - separation character
      Returns:
      resulting strings
    • split

      public static String[] split(String string, char separator, int limit)
      Splits a string around matches of the given separator.
      Parameters:
      string - string to be split
      separator - separation character
      limit - maximum number of strings (ignored if -1)
      Returns:
      resulting strings
    • delete

      public static String delete(String string, char ch)
      Deletes a character from a string.
      Parameters:
      string - string
      ch - character to be removed
      Returns:
      resulting token
    • contains

      public static boolean contains(String string, char ch)
      Checks if a string contains a character.
      Parameters:
      string - string
      ch - character to search for
      Returns:
      result of check
    • md5

      public static String md5(String string)
      Returns an MD5 hash in lower case.
      Parameters:
      string - string to be hashed
      Returns:
      md5 hash
    • sha256

      public static String sha256(String string)
      Returns an SHA256 hash in lower case.
      Parameters:
      string - string to be hashed
      Returns:
      sha256 hash
    • normEncoding

      public static String normEncoding(String encoding)
      Returns a unified representation of the specified encoding.
      Parameters:
      encoding - input encoding (UTF-8 is returned for a null reference)
      Returns:
      encoding
    • normEncoding

      public static String normEncoding(String encoding, boolean utf16)
      Returns a unified representation of the specified encoding.
      Parameters:
      encoding - input encoding (UTF-8 is returned for a null reference)
      utf16 - normalize UTF-16 encoding
      Returns:
      encoding
    • supported

      public static boolean supported(String encoding)
      Checks if the specified encoding is supported.
      Parameters:
      encoding - encoding
      Returns:
      result of check
    • capitalize

      public static String capitalize(String string)
      Capitalizes the first letter of a string.
      Parameters:
      string - input string
      Returns:
      capitalized string
    • className

      public static String className(String string)
      Converts the given string to a Java class name. Slashes will be replaced with dots, and the last package segment will be capitalized and camel-cased.
      Parameters:
      string - string to convert
      Returns:
      class name
    • camelCase

      public static String camelCase(String string)
      Converts the given string to camel case.
      Parameters:
      string - string to convert
      Returns:
      resulting string
    • no

      public static boolean no(String string)
      Checks if the specified string is "no", "false", "off" or "0".
      Parameters:
      string - string to be checked
      Returns:
      result of check
    • uri2path

      public static String uri2path(String uri)
      Converts a URI to a directory path. See https://docs.basex.org/wiki/Repository#URI_Rewriting for details.
      Parameters:
      uri - namespace uri
      Returns:
      converted path
    • startsWith

      public static boolean startsWith(String string, char ch)
      Checks if a string starts with the specified character.
      Parameters:
      string - string
      ch - character to be found
      Returns:
      result of check
    • endsWith

      public static boolean endsWith(String string, char ch)
      Checks if a string ends with the specified character.
      Parameters:
      string - string
      ch - character to be found
      Returns:
      result of check
    • concat

      public static String concat(Object... objects)
      Concatenates multiple objects.
      Parameters:
      objects - objects
      Returns:
      resulting string
    • encodings

      public static String[] encodings()
      Returns a string array with all supported encodings.
      Returns:
      encodings