java.lang.Object
io.github.darvil.utils.UtlString
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final charEscape character used for terminal formatting -
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull StringCenters a string in a given width.static @NotNull StringCenters a string in a given width.static @NotNull StringescapeQuotes(@NotNull String str) Replaces all quotes in the given string with escaped quotes.static intgetLengthIgnoreSequences(@NotNull String str) Returns the length of the string, ignoring any formatting sequences.static @NotNull StringgetLongestLine(@NotNull String str) Get the longest line from the contents of a string.static @NotNull StringAddspadCountspace characters at the left of the string.static @NotNull StringAddspadCountcharacters (specified withpadChar) at the left of the string.static booleanisNullOrBlank(@Nullable String str) Returns true if the string given isnullor blank.static booleanisNullOrEmpty(@Nullable String str) Returns true if the string given isnullor empty.static @NotNull StringReturns the count given appended to the string given.static @NotNull StringremoveSequences(@NotNull String str) Remove all formatting colors or format from the stringstatic @NotNull String @NotNull []split(String, char, int)with max set to -1.static @NotNull String @NotNull []Split a string by the given splitter.static @NotNull String @NotNull []Split a string by the given splitter.splitAtLeadingWhitespace(@NotNull String str) Returns a pair of strings.static @NotNull StringWraps a string into multiple lines in order to fit in the given maximum width.
-
Field Details
-
ESCAPE_CHAR
public static final char ESCAPE_CHAREscape character used for terminal formatting- See Also:
-
-
Method Details
-
getLongestLine
Get the longest line from the contents of a string. Lines are separated by newlines and the length is calculated without counting the escape sequences. -
wrap
Wraps a string into multiple lines in order to fit in the given maximum width. Wrapping respects words and indentation, so no word will be split in two lines and indentation will be preserved.- Parameters:
str- The text to wrap.maxWidth- The maximum width that the text should never exceed.- Returns:
- The wrapped text.
-
indent
@NotNull public static @NotNull String indent(@NotNull @NotNull String str, int padCount, char padChar) AddspadCountcharacters (specified withpadChar) at the left of the string. If the string has multiple lines, the padding is added on all of them.- Parameters:
str- The string to pad.padCount- The number of characters to add.padChar- The character to use for padding.- Returns:
- The padded string.
-
indent
AddspadCountspace characters at the left of the string. If the string has multiple lines, the padding is added on all of them.- Parameters:
str- The string to pad.padCount- The amount of spaces to add.- Returns:
- The padded string.
-
center
@NotNull public static @NotNull String center(@NotNull @NotNull String str, int width, char padChar) Centers a string in a given width.padCharis used to fill the remaining space. The padding is equal on both sides of the string, even if the width is odd.If the string is longer than the width, it is returned as is.
- Parameters:
str- The string to center.width- The width to center the string in.padChar- The character to use for padding.- Returns:
- The centered string.
-
center
Centers a string in a given width. '-' is used to fill the remaining space. The padding is equal on both sides of the string, even if the width is odd.- Parameters:
str- The string to center.width- The width to center the string in.- Returns:
- The centered string.
- See Also:
-
removeSequences
Remove all formatting colors or format from the string -
getLengthIgnoreSequences
Returns the length of the string, ignoring any formatting sequences. -
plural
Returns the count given appended to the string given. An's'will be appended at the end if the count is not 1.- Parameters:
str- the string to append tocount- the count- Returns:
- "count str" or "count strs" depending on the count
-
isNullOrEmpty
Returns true if the string given isnullor empty.- Parameters:
str- the string to check- Returns:
- true if the string is
nullor empty
-
isNullOrBlank
Returns true if the string given isnullor blank.- Parameters:
str- the string to check- Returns:
- true if the string is
nullor blank
-
split
@NotNull public static @NotNull String @NotNull [] split(@NotNull @NotNull String str, @NotNull @NotNull String splitter, int max) Split a string by the given splitter. This is similar toString.split(String)but it will also ignore spaces around the splitter.- Parameters:
str- the string to splitsplitter- the splittermax- the maximum amount of splits- Returns:
- the split string
-
split
@NotNull public static @NotNull String @NotNull [] split(@NotNull @NotNull String str, char splitter, int max) Split a string by the given splitter. This is similar toString.split(String)but it will also ignore spaces around the splitter.- Parameters:
str- the string to splitsplitter- the splitter- Returns:
- the split string
-
split
@NotNull public static @NotNull String @NotNull [] split(@NotNull @NotNull String str, char splitter) split(String, char, int)with max set to -1. (Default ofString.split(String))- See Also:
-
splitAtLeadingWhitespace
@NotNull public static @NotNull Pair<@NotNull String,@NotNull String> splitAtLeadingWhitespace(@NotNull @NotNull String str) Returns a pair of strings. The first string is the leading whitespace of the string given, and the second string is the string given without the leading whitespace.- Parameters:
str- the string to split- Returns:
- a pair of strings
-
escapeQuotes
Replaces all quotes in the given string with escaped quotes. For example,"hello'becomes\"testing\'.- Parameters:
str- the string to escape- Returns:
- the escaped string
-