mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-10 02:31:48 +00:00
added stringx.contains
This commit is contained in:
parent
77d954e58a
commit
20aa83f79e
18
stringx.lua
18
stringx.lua
@ -218,6 +218,24 @@ function stringx.apply_template(s, sub)
|
||||
return r
|
||||
end
|
||||
|
||||
--check if a given string contains another
|
||||
--(without garbage)
|
||||
function stringx.contains(haystack, needle)
|
||||
for i = 1, #haystack - #needle + 1 do
|
||||
local found = true
|
||||
for j = 1, #needle do
|
||||
if haystack:byte(i + j - 1) ~= needle:byte(j) then
|
||||
found = false
|
||||
break
|
||||
end
|
||||
end
|
||||
if found then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--check if a given string starts with another
|
||||
--(without garbage)
|
||||
function stringx.starts_with(s, prefix)
|
||||
|
Loading…
Reference in New Issue
Block a user