mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-22 14:14:36 +00:00
Added ends_with method to stringx
This commit is contained in:
parent
e8bb432999
commit
fb4c187347
13
stringx.lua
13
stringx.lua
@ -320,4 +320,17 @@ function stringx.starts_with(s, prefix)
|
||||
return true
|
||||
end
|
||||
|
||||
function stringx.ends_with(s, prefix)
|
||||
if prefix == "" then return true end
|
||||
|
||||
if #prefix > #s then return false end
|
||||
|
||||
for i = 0, #prefix-1 do
|
||||
if s:byte(#s-i) ~= prefix:byte(#prefix-i) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
return stringx
|
||||
|
Loading…
Reference in New Issue
Block a user