From 53fdb9bc72aab1bd41126be806cf58cc73e2a625 Mon Sep 17 00:00:00 2001 From: pixel Date: Mon, 28 May 2007 06:52:21 +0000 Subject: Adding split function. --- lib/supportlib.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/supportlib.lua b/lib/supportlib.lua index 8565b8e..d734a1e 100644 --- a/lib/supportlib.lua +++ b/lib/supportlib.lua @@ -102,3 +102,27 @@ function hexdump(inp, from, to, width) print(outstring) end + + +-- +-- Splits a string given a separator character into an array. +-- + +function split(str, at) + local splut = {} + + if (type(str) ~= "string") then return nil end + if (not str) then str = "" end + + if (not at) then + table.insert(splut, str) + else + for n, c in string.gfind(str, '([^%'..at..']*)(%'..at..'?)') do + table.insert(splut, n) + + if (c == '') then break end + end + end + + return splut +end -- cgit v1.2.3