From 9a8493b88005d95d495defb94d21b9c53b0131a3 Mon Sep 17 00:00:00 2001 From: Max Cahill <1bardesign@gmail.com> Date: Mon, 24 Oct 2022 16:08:39 +1100 Subject: [PATCH] added stringx.split_and_trim to save me inlining something with the same effect all over the place --- stringx.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/stringx.lua b/stringx.lua index cda2f26..0b6b865 100644 --- a/stringx.lua +++ b/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