mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-17 18:20:49 +00:00
api: return when no subject was given to strsplit
This commit is contained in:
@@ -14,6 +14,7 @@ mod = math.mod or mod
|
|||||||
-- 'subject' [string] String to split.
|
-- 'subject' [string] String to split.
|
||||||
-- return: [list] a list of strings.
|
-- return: [list] a list of strings.
|
||||||
function pfUI.api.strsplit(delimiter, subject)
|
function pfUI.api.strsplit(delimiter, subject)
|
||||||
|
if not subject then return nil end
|
||||||
local delimiter, fields = delimiter or ":", {}
|
local delimiter, fields = delimiter or ":", {}
|
||||||
local pattern = string.format("([^%s]+)", delimiter)
|
local pattern = string.format("([^%s]+)", delimiter)
|
||||||
string.gsub(subject, pattern, function(c) fields[table.getn(fields)+1] = c end)
|
string.gsub(subject, pattern, function(c) fields[table.getn(fields)+1] = c end)
|
||||||
|
|||||||
Reference in New Issue
Block a user