api: return when no subject was given to strsplit

This commit is contained in:
shagu
2019-04-02 22:42:19 +02:00
parent 07d42861a8
commit 05349d475e
+1
View File
@@ -14,6 +14,7 @@ mod = math.mod or mod
-- 'subject' [string] String to split.
-- return: [list] a list of strings.
function pfUI.api.strsplit(delimiter, subject)
if not subject then return nil end
local delimiter, fields = delimiter or ":", {}
local pattern = string.format("([^%s]+)", delimiter)
string.gsub(subject, pattern, function(c) fields[table.getn(fields)+1] = c end)