diff --git a/resources/install/scripts/resources/functions/split.lua b/resources/install/scripts/resources/functions/split.lua new file mode 100644 index 0000000000..c46e0cad0b --- /dev/null +++ b/resources/install/scripts/resources/functions/split.lua @@ -0,0 +1,27 @@ +function split(str, sep, plain) + local b, res = 1, {} + while b <= #str do + local e, e2 = string.find(str, sep, b, plain) + if e then + res[#res + 1] = string.sub(str, b, e-1) + b = e2 + 1 + else + res[#res + 1] = string.sub(str, b) + break + end + end + return res +end + +function split_first(str, sep, plain) + local e, e2 = string.find(str, sep, nil, plain) + if e then + return string.sub(str, 1, e - 1), string.sub(str, e2 + 1) + end + return str +end + +local unpack = unpack or table.unpack + +function usplit(...) return unpack(split(...)) end +