api: replace strsplit function

This commit is contained in:
shagu
2017-02-07 22:04:38 +01:00
parent 1323a75a06
commit fdac6c5d06
Vendored
+4 -12
View File
@@ -7,18 +7,10 @@ pfUI.api = { }
-- '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)
local ret = {} local delimiter, fields = delimiter or ":", {}
local sector = subject local pattern = string.format("([^%s]+)", delimiter)
while true do string.gsub(subject, pattern, function(c) fields[table.getn(fields)+1] = c end)
local pos = strfind(sector, delimiter) return unpack(fields)
if pos then
table.insert(ret, strsub(sector,1,pos-1))
sector = strsub(sector,pos+1)
else
table.insert(ret, sector)
return unpack(ret)
end
end
end end
-- [ strvertical ] -- [ strvertical ]