From 13a8edb2e740da52de6fb5b28d5ff5a84a5710b1 Mon Sep 17 00:00:00 2001 From: rxi Date: Wed, 19 Mar 2014 12:51:35 +0000 Subject: [PATCH] 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) --- lume.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lume.lua b/lume.lua index b50526b..db796c3 100644 --- a/lume.lua +++ b/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