Class UnicodeString
java.lang.Object
de.gustavblass.commons.UnicodeString
- All Implemented Interfaces:
CharSequence
Represents a Unicode string which can be manipulated by
censoring and
strikeThrough()
. Counts emojis as one character each.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final org.apache.logging.log4j.Logger
private final char @NonNull []
The actual text represented by thisUnicodeString
-
Constructor Summary
ConstructorsConstructorDescriptionUnicodeString
(char @NonNull [] string) Creates a newUnicodeString
from the givenchar
array.UnicodeString
(@NonNull String string) Creates a newUnicodeString
from the givenString
. -
Method Summary
Modifier and TypeMethodDescription@NonNull String
censor()
Replaces all characters in thestring
with asterisks.char
charAt
(int index) @NonNull IntStream
chars()
@NonNull IntStream
boolean
isEmpty()
int
length()
@NonNull String
Converts the given input string to a struck-through version of itself.@NotNull UnicodeString
subSequence
(int start, int end) @NonNull String
toString()
-
Field Details
-
LOG
private static final org.apache.logging.log4j.Logger LOG -
string
private final char @NonNull [] stringThe actual text represented by thisUnicodeString
-
-
Constructor Details
-
UnicodeString
Creates a newUnicodeString
from the givenString
.- Parameters:
string
- The content of the new UnicodeString.
-
UnicodeString
public UnicodeString(char @NonNull [] string) Creates a newUnicodeString
from the givenchar
array.- Parameters:
string
- The content of the new UnicodeString.
-
-
Method Details
-
censor
Replaces all characters in thestring
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
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 thestring
, 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()- Specified by:
length
in interfaceCharSequence
- Returns:
- The number of characters.
- See Also:
-
charAt
- Specified by:
charAt
in interfaceCharSequence
- Throws:
IndexOutOfBoundsException
- If the index is smaller than 0 or exceeds thestring
's length.
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCharSequence
-
subSequence
@NotNull public @NotNull UnicodeString subSequence(int start, int end) throws IndexOutOfBoundsException - Specified by:
subSequence
in interfaceCharSequence
- Throws:
IndexOutOfBoundsException
- If the start index is smaller than 0 or greater than thestring
's length, or if the end index is smaller than the start index or greater than thestring
's length.
-
toString
- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
-
chars
- Specified by:
chars
in interfaceCharSequence
-
codePoints
- Specified by:
codePoints
in interfaceCharSequence
-