[modified] stringx.starts_with to not generate garbage

This commit is contained in:
Max Cahill 2021-03-02 11:47:28 +11:00
parent dfd1a1c69f
commit 290b39236c

View File

@ -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