mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-15 09:40:49 +00:00
api: replace strsplit function
This commit is contained in:
Vendored
+4
-12
@@ -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 ]
|
||||||
|
|||||||
Reference in New Issue
Block a user