mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-26 07:34:35 +00:00
[modified] stringx.starts_with to not generate garbage
This commit is contained in:
parent
dfd1a1c69f
commit
290b39236c
11
stringx.lua
11
stringx.lua
@ -280,8 +280,15 @@ function stringx.apply_template(s, sub)
|
|||||||
return r
|
return r
|
||||||
end
|
end
|
||||||
|
|
||||||
function stringx.starts_with(s, start)
|
--check if a given string starts with another
|
||||||
return s:sub(1, #start) == start
|
--(without garbage)
|
||||||
|
function stringx.starts_with(s, prefix)
|
||||||
|
for i = 1, #prefix do
|
||||||
|
if s:byte(i) ~= prefix:byte(i) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
return stringx
|
return stringx
|
||||||
|
Loading…
Reference in New Issue
Block a user