mirror of
https://github.com/TangentFoxy/lume.git
synced 2024-11-19 07:04:24 +00:00
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:
parent
425a52b99f
commit
13a8edb2e7
8
lume.lua
8
lume.lua
@ -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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user