mirror of
https://github.com/TangentFoxy/lume.git
synced 2025-07-28 11:02:20 +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:
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
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user