added stringx.split_and_trim to save me inlining something with the same effect all over the place

This commit is contained in:
Max Cahill 2022-10-24 16:08:39 +11:00
parent 84d4e39622
commit 9a8493b880

View File

@ -272,4 +272,20 @@ function stringx.ends_with(s, suffix)
return true return true
end end
--split elements by delimiter and trim the results, discarding empties
--useful for hand-entered "permissive" data
-- "a,b, c, " -> {"a", "b", "c"}
function stringx.split_and_trim(s, delim)
s = stringx.split(s, delim)
for i = #s, 1, -1 do
local v = stringx.trim(s[i])
if v == "" then
table.remove(s, i)
else
s[i] = v
end
end
return s
end
return stringx return stringx