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.Loggerprivate final char @NonNull []The actual text represented by thisUnicodeString -
Constructor Summary
ConstructorsConstructorDescriptionUnicodeString(char @NonNull [] string) Creates a newUnicodeStringfrom the givenchararray.UnicodeString(@NonNull String string) Creates a newUnicodeStringfrom the givenString. -
Method Summary
Modifier and TypeMethodDescription@NonNull Stringcensor()Replaces all characters in thestringwith asterisks.charcharAt(int index) @NonNull IntStreamchars()@NonNull IntStreambooleanisEmpty()intlength()@NonNull StringConverts the given input string to a struck-through version of itself.@NotNull UnicodeStringsubSequence(int start, int end) @NonNull StringtoString()
-
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 newUnicodeStringfrom the givenString.- Parameters:
string- The content of the new UnicodeString.
-
UnicodeString
public UnicodeString(char @NonNull [] string) Creates a newUnicodeStringfrom the givenchararray.- Parameters:
string- The content of the new UnicodeString.
-
-
Method Details
-
censor
Replaces all characters in thestringwith asterisks. This is useful for censoring sensitive information such as passwords or personal data. For example,xkeyscorewould 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:
lengthin interfaceCharSequence- Returns:
- The number of characters.
- See Also:
-
charAt
- Specified by:
charAtin interfaceCharSequence- Throws:
IndexOutOfBoundsException- If the index is smaller than 0 or exceeds thestring's length.
-
isEmpty
@Contract(pure=true) public boolean isEmpty()- Specified by:
isEmptyin interfaceCharSequence
-
subSequence
@Contract(pure=true) @NotNull public @NotNull UnicodeString subSequence(int start, int end) throws IndexOutOfBoundsException - Specified by:
subSequencein 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:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-
chars
- Specified by:
charsin interfaceCharSequence
-
codePoints
- Specified by:
codePointsin interfaceCharSequence
-