Methods


StringUtils.contains(str: string, filter: string)

Returns whether a string contains a given substring

@param str — The string to check.

@param filter — The substring that the string may contain.

@return result — Whether the string contained the specified substring.

Arguments:

str: string

The string to check.

filter: string

The substring that the string may contain.

Returns:

result: boolean

Whether the string contained the specified substring.



StringUtils.endsWith(value: string, suffix: string)

Returns whether a string ends with the specified substring.
The function will also return a second value, created by copying the initial value and removing the suffix.

@param value — The value to check the end of.

@param suffix — The prefix that should be checked.

@return success — Whether the value ended with the specified suffix.

@return rest — A new value created by removing the suffix substring or values from the initial value. If the result was unsuccessful, this value will simply be the initial unedited value.

Arguments:

value: string

The value to check the end of.

suffix: string

The prefix that should be checked.

Returns:

success: boolean

Whether the value ended with the specified suffix.

rest: string

A new value created by removing the suffix substring or values from the initial value. If the result was unsuccessful, this value will simply be the initial unedited value.



StringUtils.format(str: string, tbl: table)

This function substitutes values from a table into a string using placeholders in the form of {key} or {}, where the latter indexes the table by number.

@param str — The string to substitute values into.

@param tbl — The table containing the values to substitute.

@return result — The formatted string.

Arguments:

str: string

The string to substitute values into.

tbl: table

The table containing the values to substitute.

Returns:

result: string

The formatted string.



StringUtils.insert(str1: string, str2: string, pos: integer)

Inserts a string into a different string at the specified position.

@param str1 — The string to receive the substring.

@param str2 — The substring to insert into the main string.

@param pos — The position at which to insert the string.

@return result — The newly created string.

Arguments:

str1: string

The string to receive the substring.

str2: string

The substring to insert into the main string.

pos: integer

The position at which to insert the string.

Returns:

result: string

The newly created string.



StringUtils.len(input: string)

Returns the length of a string, while being UTF-8 aware.

@param input — The string to get the length of.

@return length — The length of the string.

Arguments:

input: string

The string to get the length of.

Returns:

length: integer

The length of the string.



StringUtils.pad(str: string, len: number, beginning: boolean?, with: string?)

Returns a string with a specified length, filling it with empty spaces by default. Used to make strings consistent lengths for UI.
If the specified string has a length greater than the desired length, it will not be adjusted.

@param str — The string to extend.

@param len — The amount of characters the returned string should be.

@param beginning — If true, the beginning of the string will be filled instead of the end.

@param with — If specified, the string will be filled with this specified string, instead of with spaces.

@return result — The new padded result.

Arguments:

str: string

The string to extend.

len: number

The amount of characters the returned string should be.

beginning: boolean?

If true, the beginning of the string will be filled instead of the end.

with: string?

If specified, the string will be filled with this specified string, instead of with spaces.

Returns:

result: string

The new padded result.



StringUtils.split(input: string, separator: string, remove_empty: boolean?)

Splits a string into a new table of strings using a substring as a separator.
Less optimized than Utils.splitFast(), but allows separating with multiple characters, and is more likely to work for any string.

@param input — The string to separate.

@param separator — The substring used to split the main string.

@param remove_empty — Whether strings containing no characters shouldn't be included in the result table.

@return result — The table containing the new split strings.

Arguments:

input: string

The string to separate.

separator: string

The substring used to split the main string.

remove_empty: boolean?

Whether strings containing no characters shouldn't be included in the result table.

Returns:

result: string[]

The table containing the new split strings.



StringUtils.splitFast(input: string, separator: string)

Splits a string into a new table of strings using a single character as a separator.
More optimized than Utils.split(), at the cost of lacking features.
Note: This function uses gmatch, so special characters must be escaped with a %.

@param input — The string to separate.

@param separator — The character used to split the main string.

@return result — The table containing the new split strings.

Arguments:

input: string

The string to separate.

separator: string

The character used to split the main string.

Returns:

result: string[]

The table containing the new split strings.



StringUtils.squishAndTrunc(str: string, font: love.Font, max_width: number, def_scale: number?, min_scale: number?, trunc_affix: (string|false)?)

Finds and returns the scale required to print str with the font font, such that it's width does not exceed max_width.
If a min_scale is specified, strings that would have to be squished smaller than it will instead have their remaining part truncated.
Returns the input string (truncated if necessary), and the scale to print it at.

@param str — The string to squish and truncate.

@param font — The font being used to print the string.

@param max_width — The maximum width the string should be able to take up.

@param def_scale — The default scale used to print the string. Defaults to 1.

@param min_scale — The minimum scale that the string can be squished to before being truncated.

@param trunc_affix — The affix added to the string during truncation. If false, does not add an affix. Defaults to ....

@return result — The truncated result. Returns the original string if it was not truncated.

@return scale — The scale the result string should be printed at to fit within the specified width.

trunc_affix:
    | false

Arguments:

str: string

The string to squish and truncate.

font: love.Font

The font being used to print the string.

max_width: number

The maximum width the string should be able to take up.

def_scale: number?

The default scale used to print the string. Defaults to 1.

min_scale: number?

The minimum scale that the string can be squished to before being truncated.

trunc_affix: (string|false)?

The affix added to the string during truncation. If false, does not add an affix. Defaults to ....

Returns:

result: string

The truncated result. Returns the original string if it was not truncated.

scale: number

The scale the result string should be printed at to fit within the specified width.



StringUtils.startsWith(value: string, prefix: string)

Returns whether a string starts with the specified substring.
The function will also return a second value, created by copying the initial value and removing the prefix.

@param value — The value to check the beginning of.

@param prefix — The prefix that should be checked.

@return success — Whether the value started with the specified prefix.

@return rest — A new value created by removing the prefix substring or values from the initial value. If the result was unsuccessful, this value will simply be the initial unedited value.

Arguments:

value: string

The value to check the beginning of.

prefix: string

The prefix that should be checked.

Returns:

success: boolean

Whether the value started with the specified prefix.

rest: string

A new value created by removing the prefix substring or values from the initial value. If the result was unsuccessful, this value will simply be the initial unedited value.



StringUtils.sub(input: string, from: integer?, to: integer?)

Returns a substring of the specified string, properly accounting for UTF-8.

@param input — The initial string to get a substring of.

@param from — The index that the substring should start at. (Defaults to 1, referring to the first character of the string)

@param to — The index that the substring should end at. (Defaults to -1, referring to the last character of the string)

@return substring — The new substring.

Arguments:

input: string

The initial string to get a substring of.

from: integer?

The index that the substring should start at. (Defaults to 1, referring to the first character of the string)

to: integer?

The index that the substring should end at. (Defaults to -1, referring to the last character of the string)

Returns:

substring: string

The new substring.



StringUtils.titleCase(str: string)

Converts a string into a new string where the first letter of each "word" (determined by spaces between characters) will be capitalized.

@param str — The initial string to edit.

@return result — The new string, in Title Case.

Arguments:

str: string

The initial string to edit.

Returns:

result: string

The new string, in Title Case.



StringUtils.trim(str: string)

Strips a string of padding whitespace.

@param str — The initial string to edit.

@return result — The new string, without padding whitespace.

Arguments:

str: string

The initial string to edit.

Returns:

result: string

The new string, without padding whitespace.




Fields



Undocumented