Class UnicodeString

java.lang.Object
de.gustavblass.commons.UnicodeString
All Implemented Interfaces:
CharSequence

public class UnicodeString extends Object implements CharSequence
Represents a Unicode string which can be manipulated by censoring and strikeThrough(). Counts emojis as one character each.
  • Field Details

    • LOG

      private static final org.apache.logging.log4j.Logger LOG
    • string

      private final char @NonNull [] string
      The actual text represented by this UnicodeString
  • Constructor Details

    • UnicodeString

      public UnicodeString(@NonNull @NonNull String string)
      Creates a new UnicodeString from the given String.
      Parameters:
      string - The content of the new UnicodeString.
    • UnicodeString

      public UnicodeString(char @NonNull [] string)
      Creates a new UnicodeString from the given char array.
      Parameters:
      string - The content of the new UnicodeString.
  • Method Details

    • censor

      @Contract(pure=true) @NonNull public @NonNull String censor()
      Replaces all characters in the string with asterisks. This is useful for censoring sensitive information such as passwords or personal data. For example, xkeyscore would be censored to *********.
      Returns:
      The censored version of the input text.
    • strikeThrough

      @Contract(pure=true) @NonNull public @NonNull String strikeThrough()
      Converts the given input string to a struck-through version of itself. This is done by appending a Unicode strike-through symbol to each character present in the string, which creates a line that runs horizontally through the middle of the entire text.
      Returns:
      The struck-through version of the input text.
    • length

      @Contract(pure=true) public int length()
      Counts the number of characters in the string, but treats each emoji as only one character.
      Specified by:
      length in interface CharSequence
      Returns:
      The number of characters.
      See Also:
    • charAt

      public char charAt(int index) throws IndexOutOfBoundsException
      Specified by:
      charAt in interface CharSequence
      Throws:
      IndexOutOfBoundsException - If the index is smaller than 0 or exceeds the string's length.
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface CharSequence
    • subSequence

      @NotNull public @NotNull UnicodeString subSequence(int start, int end) throws IndexOutOfBoundsException
      Specified by:
      subSequence in interface CharSequence
      Throws:
      IndexOutOfBoundsException - If the start index is smaller than 0 or greater than the string's length, or if the end index is smaller than the start index or greater than the string's length.
    • toString

      @NonNull public @NonNull String toString()
      Specified by:
      toString in interface CharSequence
      Overrides:
      toString in class Object
    • chars

      @NonNull public @NonNull IntStream chars()
      Specified by:
      chars in interface CharSequence
    • codePoints

      @NonNull public @NonNull IntStream codePoints()
      Specified by:
      codePoints in interface CharSequence