diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2023-03-17 21:18:17 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2023-03-17 21:40:51 -0700 |
commit | ae429cd78a1f52272d5f51991ebb9b04b542ce01 (patch) | |
tree | cfc3a8509ac7b47341507da2c614f0588601fccc /source_text.lua | |
parent | 81ebc6a55998f59c34a725bd47d77e88fb0eb341 (diff) | |
download | text.love-ae429cd78a1f52272d5f51991ebb9b04b542ce01.tar.gz |
bring a few things in sync between run and source
Diffstat (limited to 'source_text.lua')
-rw-r--r-- | source_text.lua | 24 |
1 files changed, 20 insertions, 4 deletions
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 |