[spec/*,*] Split library in submodules.

This commit is contained in:
2022-08-16 00:10:09 +02:00
parent e658ba45c7
commit 0e2dd54011
7 changed files with 811 additions and 517 deletions

28
strings.lua Normal file
View File

@ -0,0 +1,28 @@
local strings = {}
--- Test whether a string starts with a prefix.
function strings.startswith(s, prefix)
-- optimized version of: return s:sub(1, #prefix) == prefix
for i = 1,#prefix do
if s:byte(i) ~= prefix:byte(i) then
return false
end
end
return true
end
--- Test whether a string ends with a trailing suffix.
function strings.endswith(s, trailing)
-- optimized version of: return trailing == "" or s:sub(-#trailing) == trailing
local n1,n2 = #s,#trailing
for i = 0,n2-1 do
if s:byte(n1-i) ~= trailing:byte(n2-i) then
return false
end
end
return true
end
return strings