Top Fields Constructors Methods
io.github.darvil.utils

public final Class UtlString

extends Object
Class Inheritance
Imports
org.jetbrains.annotations.NotNull, .Nullable, java.util.regex.Pattern, java.util.stream.Stream

Field Summary

Modifier and TypeField and Description
public static final char
ESCAPE_CHAR

Escape character used for terminal formatting

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static @NotNull String

Returns:

The centered string.
center
(@NotNull String
The string to center.
str
,
int
The width to center the string in.
width
,
char
The character to use for padding.
padChar
)

Centers a string in a given width.

public static @NotNull String

Returns:

The centered string.
center
(@NotNull String
The string to center.
str
,
int
The width to center the string in.
width
)

Centers a string in a given width.

public static @NotNull String

Returns:

the escaped string
escapeQuotes
(@NotNull String
the string to escape
str
)

Replaces all quotes in the given string with escaped quotes.

public static int
getLengthIgnoreSequences(@NotNull String str)

Returns the length of the string, ignoring any formatting sequences.

public static @NotNull String
getLongestLine(@NotNull String str)

Get the longest line from the contents of a string.

public static @NotNull String

Returns:

The padded string.
indent
(@NotNull String
The string to pad.
str
,
int
The number of characters to add.
padCount
,
char
The character to use for padding.
padChar
)

Adds padCount characters (specified with padChar) at the left of the string.

public static @NotNull String

Returns:

The padded string.
indent
(@NotNull String
The string to pad.
str
,
int
The amount of spaces to add.
padCount
)

Adds padCount space characters at the left of the string.

public static boolean

Returns:

true if the string is null or blank
isNullOrBlank
(@Nullable String
the string to check
str
)

Returns true if the string given is null or blank.

public static boolean

Returns:

true if the string is null or empty
isNullOrEmpty
(@Nullable String
the string to check
str
)

Returns true if the string given is null or empty.

public static @NotNull String

Returns:

"count str" or "count strs" depending on the count
plural
(@NotNull String
the string to append to
str
,
int
the count
count
)

Returns the count given appended to the string given.

public static @NotNull String
removeSequences(@NotNull String str)

Remove all formatting colors or format from the string

public static @NotNull @NotNull String[]

Returns:

the split string
split
(@NotNull String
the string to split
str
,
@NotNull String
the splitter
splitter
,
int
the maximum amount of splits
max
)

Split a string by the given splitter.

public static @NotNull @NotNull String[]

Returns:

the split string
split
(@NotNull String
the string to split
str
,
char
the splitter
splitter
,
int max)

Split a string by the given splitter.

public static @NotNull @NotNull String[]
split(@NotNull String str, char splitter)

UtlString#split(String, char, int) with max set to -1.

public static @NotNull Pair<@NotNull String, @NotNull String>

Returns:

a pair of strings
splitAtLeadingWhitespace
(@NotNull String
the string to split
str
)

Returns a pair of strings.

public static @NotNull String

Returns:

The wrapped text.
wrap
(@NotNull String
The text to wrap.
str
,
int
The maximum width that the text should never exceed.
maxWidth
)

Wraps a string into multiple lines in order to fit in the given maximum width.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ESCAPE_CHARback to summary
public static final char ESCAPE_CHAR

Escape character used for terminal formatting

Constructor Detail

UtlStringback to summary
private UtlString()

Method Detail

centerback to summary
public static @NotNull String center(@NotNull String str, int width, char padChar)

Centers a string in a given width. padChar is 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:@NotNull String

The string to center.

width:int

The width to center the string in.

padChar:char

The character to use for padding.

Returns:@NotNull String

The centered string.

Annotations
@NotNull
centerback to summary
public static @NotNull String center(@NotNull String str, int width)

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:@NotNull String

The string to center.

width:int

The width to center the string in.

Returns:@NotNull String

The centered string.

Annotations
@NotNull
See Also
UtlString#center(String, int, char)
escapeQuotesback to summary
public static @NotNull String escapeQuotes(@NotNull String str)

Replaces all quotes in the given string with escaped quotes. For example, "hello' becomes \"testing\'.

Parameters
str:@NotNull String

the string to escape

Returns:@NotNull String

the escaped string

Annotations
@NotNull
getLengthIgnoreSequencesback to summary
public static int getLengthIgnoreSequences(@NotNull String str)

Returns the length of the string, ignoring any formatting sequences.

getLongestLineback to summary
public static @NotNull String getLongestLine(@NotNull String str)

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.

Annotations
@NotNull
indentback to summary
public static @NotNull String indent(@NotNull String str, int padCount, char padChar)

Adds padCount characters (specified with padChar) at the left of the string. If the string has multiple lines, the padding is added on all of them.

Parameters
str:@NotNull String

The string to pad.

padCount:int

The number of characters to add.

padChar:char

The character to use for padding.

Returns:@NotNull String

The padded string.

Annotations
@NotNull
indentback to summary
public static @NotNull String indent(@NotNull String str, int padCount)

Adds padCount space characters at the left of the string. If the string has multiple lines, the padding is added on all of them.

Parameters
str:@NotNull String

The string to pad.

padCount:int

The amount of spaces to add.

Returns:@NotNull String

The padded string.

Annotations
@NotNull
isNullOrBlankback to summary
public static boolean isNullOrBlank(@Nullable String str)

Returns true if the string given is null or blank.

Parameters
str:@Nullable String

the string to check

Returns:boolean

true if the string is null or blank

isNullOrEmptyback to summary
public static boolean isNullOrEmpty(@Nullable String str)

Returns true if the string given is null or empty.

Parameters
str:@Nullable String

the string to check

Returns:boolean

true if the string is null or empty

pluralback to summary
public static @NotNull String plural(@NotNull String str, int count)

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:@NotNull String

the string to append to

count:int

the count

Returns:@NotNull String

"count str" or "count strs" depending on the count

Annotations
@NotNull
removeSequencesback to summary
public static @NotNull String removeSequences(@NotNull String str)

Remove all formatting colors or format from the string

Annotations
@NotNull
splitback to summary
public static @NotNull @NotNull String[] split(@NotNull String str, @NotNull String splitter, int max)

Split a string by the given splitter. This is similar to String#split(String) but it will also ignore spaces around the splitter.

Parameters
str:@NotNull String

the string to split

splitter:@NotNull String

the splitter

max:int

the maximum amount of splits

Returns:@NotNull @NotNull String[]

the split string

Annotations
@NotNull
splitback to summary
public static @NotNull @NotNull String[] split(@NotNull String str, char splitter, int max)

Split a string by the given splitter. This is similar to String#split(String) but it will also ignore spaces around the splitter.

Parameters
str:@NotNull String

the string to split

splitter:char

the splitter

Returns:@NotNull @NotNull String[]

the split string

Annotations
@NotNull
splitback to summary
public static @NotNull @NotNull String[] split(@NotNull String str, char splitter)

UtlString#split(String, char, int) with max set to -1. (Default of String#split(String))

Annotations
@NotNull
See Also
UtlString#split(String, char, int)
splitAtLeadingWhitespaceback to summary
public static @NotNull Pair<@NotNull String, @NotNull String> splitAtLeadingWhitespace(@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:@NotNull String

the string to split

Returns:@NotNull Pair<@NotNull String, @NotNull String>

a pair of strings

Annotations
@NotNull
wrapback to summary
public static @NotNull String wrap(@NotNull String str, int maxWidth)

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:@NotNull String

The text to wrap.

maxWidth:int

The maximum width that the text should never exceed.

Returns:@NotNull String

The wrapped text.

Annotations
@NotNull