Methods
StringUtils.contains(str: string, filter: string)
Returns whether a string contains a given 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.
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.
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.
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.
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.
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.
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 %.
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.
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 |
| 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 |
Returns:
| result: string | The truncated result. Returns the original string if it was not truncated. |
| scale: number | The scale the |
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.
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.
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.
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.
Arguments:
| str: string | The initial string to edit. |
Returns:
| result: string | The new string, without padding whitespace. |