mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-22 14:14:36 +00:00
added stringx.split_and_trim to save me inlining something with the same effect all over the place
This commit is contained in:
parent
84d4e39622
commit
9a8493b880
16
stringx.lua
16
stringx.lua
@ -272,4 +272,20 @@ function stringx.ends_with(s, suffix)
|
||||
return true
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user