Changed lume.split() to mimic python's str.split()

The lume.split() function now mimics python's str.split() function,
though it does not support the third argument (maxsplit)
This commit is contained in:
rxi 2014-03-19 12:51:35 +00:00
parent 425a52b99f
commit 13a8edb2e7

View File

@ -277,7 +277,13 @@ end
function lume.split(str, sep)
return lume.array(str:gmatch("([^" .. (sep or "%s") .. "]+)"))
if not sep then
return lume.array(str:gmatch("([%S]+)"))
else
assert(sep ~= "", "empty separator")
local ssep = sep:gsub("[%(%)%.%%%+%-%*%?%[%^%$]", "%%%1")
return lume.array((str..sep):gmatch("(.-)("..ssep..")"))
end
end