Class Strings

java.lang.Object
io.bytestreams.codec.core.util.Strings

public final class Strings extends Object
Utility methods for string operations.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    Returns the number of Unicode code points in the string.
    static int
    hexByteCount(int digits)
    Returns the number of bytes represented by the given number of hex digits (two digits per byte).
    static int
    Returns the number of bytes represented by the hex string (two hex digits per byte).
    static boolean
    Returns whether the charset uses at most one byte per character.
    padEnd(char padding, int length)
    Returns a function that pads the end of a string with the specified character until it reaches the desired length.
    static String
    padEnd(String value, char padding, int length)
    Pads the end of a string with the specified character until it reaches the desired length.
    padStart(char padding, int length)
    Returns a function that pads the start of a string with the specified character until it reaches the desired length.
    static String
    padStart(String value, char padding, int length)
    Pads the start of a string with the specified character until it reaches the desired length.
    static String
    stripEnd(String value, char padding)
    Strips trailing occurrences of the specified character from the string.
    static String
    stripStart(String value, char padding)
    Strips leading occurrences of the specified character from the string.

    Methods inherited from class java.lang.Object

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

    • padStart

      public static String padStart(String value, char padding, int length)
      Pads the start of a string with the specified character until it reaches the desired length.
      Parameters:
      value - the string to pad
      padding - the character to use for padding
      length - the target length
      Returns:
      the padded string, or the original string if already at or above the target length
    • padEnd

      public static String padEnd(String value, char padding, int length)
      Pads the end of a string with the specified character until it reaches the desired length.
      Parameters:
      value - the string to pad
      padding - the character to use for padding
      length - the target length
      Returns:
      the padded string, or the original string if already at or above the target length
    • padStart

      public static Function<String,String> padStart(char padding, int length)
      Returns a function that pads the start of a string with the specified character until it reaches the desired length.
      Parameters:
      padding - the character to use for padding
      length - the target length
      Returns:
      a function that pads strings on the left
    • padEnd

      public static Function<String,String> padEnd(char padding, int length)
      Returns a function that pads the end of a string with the specified character until it reaches the desired length.
      Parameters:
      padding - the character to use for padding
      length - the target length
      Returns:
      a function that pads strings on the right
    • stripStart

      public static String stripStart(String value, char padding)
      Strips leading occurrences of the specified character from the string.
      Parameters:
      value - the string to strip
      padding - the character to strip
      Returns:
      the stripped string
    • stripEnd

      public static String stripEnd(String value, char padding)
      Strips trailing occurrences of the specified character from the string.
      Parameters:
      value - the string to strip
      padding - the character to strip
      Returns:
      the stripped string
    • isSingleByte

      public static boolean isSingleByte(Charset charset)
      Returns whether the charset uses at most one byte per character.
      Parameters:
      charset - the charset to check
      Returns:
      true if the charset is single-byte
    • codePointCount

      public static int codePointCount(String value)
      Returns the number of Unicode code points in the string.
      Parameters:
      value - the string to count code points in
      Returns:
      the number of code points
    • hexByteCount

      public static int hexByteCount(String value)
      Returns the number of bytes represented by the hex string (two hex digits per byte).
      Parameters:
      value - the hex string to count bytes in
      Returns:
      the number of bytes
    • hexByteCount

      public static int hexByteCount(int digits)
      Returns the number of bytes represented by the given number of hex digits (two digits per byte).
      Parameters:
      digits - the number of hex digits
      Returns:
      the number of bytes