mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 15:33:00 +00:00
stings/polyfill: add str_ends
....because seriously, Lua *really* should have this.
This commit is contained in:
parent
d60d3073bd
commit
1e9a651537
1 changed files with 10 additions and 0 deletions
|
@ -26,6 +26,14 @@ local function str_starts(str, start)
|
||||||
return string.sub(str, 1, string.len(start)) == start
|
return string.sub(str, 1, string.len(start)) == start
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Equivalent to string.endsWith in JS
|
||||||
|
-- @param str string The string to operate on
|
||||||
|
-- @param substr_end number The ending string to look for
|
||||||
|
-- @returns bool Whether substr_end is present at the end of str
|
||||||
|
local function str_ends(str, substr_end)
|
||||||
|
return string.sub(str, -string.len(substr_end)) == substr_end
|
||||||
|
end
|
||||||
|
|
||||||
--- Trims whitespace from a string from the beginning and the end.
|
--- Trims whitespace from a string from the beginning and the end.
|
||||||
-- From http://lua-users.org/wiki/StringTrim
|
-- From http://lua-users.org/wiki/StringTrim
|
||||||
-- @param str string The string to trim the whitespace from.
|
-- @param str string The string to trim the whitespace from.
|
||||||
|
@ -39,12 +47,14 @@ if worldeditadditions then
|
||||||
worldeditadditions.str_padend = str_padend
|
worldeditadditions.str_padend = str_padend
|
||||||
worldeditadditions.str_padstart = str_padstart
|
worldeditadditions.str_padstart = str_padstart
|
||||||
worldeditadditions.str_starts = str_starts
|
worldeditadditions.str_starts = str_starts
|
||||||
|
worldeditadditions.str_ends = str_starts
|
||||||
worldeditadditions.trim = trim
|
worldeditadditions.trim = trim
|
||||||
else
|
else
|
||||||
return {
|
return {
|
||||||
str_padend = str_padend,
|
str_padend = str_padend,
|
||||||
str_padstart = str_padstart,
|
str_padstart = str_padstart,
|
||||||
str_starts = str_starts,
|
str_starts = str_starts,
|
||||||
|
str_ends = str_starts,
|
||||||
trim = trim
|
trim = trim
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue