about summary refs log tree commit diff stats
path: root/source_text.lua
diff options
context:
space:
mode:
Diffstat (limited to 'source_text.lua')
-rw-r--r--source_text.lua24
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