From ae429cd78a1f52272d5f51991ebb9b04b542ce01 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 17 Mar 2023 21:18:17 -0700 Subject: bring a few things in sync between run and source --- source_text.lua | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'source_text.lua') diff --git a/source_text.lua b/source_text.lua index 7c00191..1a43842 100644 --- a/source_text.lua +++ b/source_text.lua @@ -1721,10 +1721,26 @@ function rtrim(s) return s:gsub('%s+$', '') end -function starts_with(s, sub) - return s:find(sub, 1, --[[no escapes]] true) == 1 +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, sub) - return s:reverse():find(sub:reverse(), 1, --[[no escapes]] true) == 1 +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 -- cgit 1.4.1-2-gfad0