From 290b39236c600909bd8dc0aed2630e49c5df3fbe Mon Sep 17 00:00:00 2001 From: Max Cahill <1bardesign@gmail.com> Date: Tue, 2 Mar 2021 11:47:28 +1100 Subject: [PATCH] [modified] stringx.starts_with to not generate garbage --- stringx.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/stringx.lua b/stringx.lua index d1880eb..f639606 100644 --- a/stringx.lua +++ b/stringx.lua @@ -280,8 +280,15 @@ function stringx.apply_template(s, sub) return r end -function stringx.starts_with(s, start) - return s:sub(1, #start) == start +--check if a given string starts with another +--(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 return stringx