Merge text.love
This commit is contained in:
commit
e80f48506d
|
@ -116,6 +116,8 @@ function find(s, pat, i, plain)
|
|||
return s:find(pat, i, plain)
|
||||
end
|
||||
|
||||
-- TODO: avoid the expensive reverse() operations
|
||||
-- Particularly if we only care about literal matches, we don't need all of string.find
|
||||
function rfind(s, pat, i, plain)
|
||||
if s == nil then return end
|
||||
local rs = s:reverse()
|
||||
|
|
24
text.lua
24
text.lua
|
@ -931,3 +931,27 @@ end
|
|||
function rtrim(s)
|
||||
return s:gsub('%s+$', '')
|
||||
end
|
||||
|
||||
function starts_with(s, prefix)
|
||||
if #s < #prefix then
|
||||
return false
|
||||
end
|
||||
for i=1,#prefix do
|
||||
if s:sub(i,i) ~= prefix:sub(i,i) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function ends_with(s, suffix)
|
||||
if #s < #suffix then
|
||||
return false
|
||||
end
|
||||
for i=0,#suffix-1 do
|
||||
if s:sub(#s-i,#s-i) ~= suffix:sub(#suffix-i,#suffix-i) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue