]> git.lizzy.rs Git - dragonblocks3d-lua.git/blob - util/split.lua
Added task manager and window
[dragonblocks3d-lua.git] / util / split.lua
1 function string.split(str, delim, include_empty, max_splits, sep_is_pattern)
2         delim = delim or ","
3         max_splits = max_splits or -2
4         local items = {}
5         local pos, len = 1, #str
6         local plain = not sep_is_pattern
7         max_splits = max_splits + 1
8         repeat
9                 local np, npe = string.find(str, delim, pos, plain)
10                 np, npe = (np or (len+1)), (npe or (len+1))
11                 if (not np) or (max_splits == 1) then
12                         np = len + 1
13                         npe = np
14                 end
15                 local s = string.sub(str, pos, np - 1)
16                 if include_empty or (s ~= "") then
17                         max_splits = max_splits - 1
18                         items[#items + 1] = s
19                 end
20                 pos = npe + 1
21         until (max_splits == 0) or (pos > (len + 1))
22         return items
23 end