Added ends_with method to stringx

This commit is contained in:
Alvaro Frias Garay 2021-04-07 13:59:42 -03:00
parent e8bb432999
commit fb4c187347

View File

@ -320,4 +320,17 @@ function stringx.starts_with(s, prefix)
return true return true
end 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 return stringx