diff options
Diffstat (limited to 'xmake/core/base/string.lua')
| -rw-r--r-- | xmake/core/base/string.lua | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/xmake/core/base/string.lua b/xmake/core/base/string.lua index 878a2f683..d031a228f 100644 --- a/xmake/core/base/string.lua +++ b/xmake/core/base/string.lua @@ -163,11 +163,18 @@ end -- ("1\n\n2\n3"):split('\n', {plain = true, strict = true}) => 1, , 2, 3 -- ("abc123123xyz123abc"):split('123', {plain = true, strict = true}) => abc, , xyz, abc -- +-- limit split count +-- ("1\n\n2\n3"):split('\n', {limit = 2}) => 1, 2\n3 +-- ("1.2.3.4.5"):split('%.', {limit = 3}) => 1, 2, 3.4.5 +-- function string:split(delimiter, opt) local result = {} local start = 1 local pos, epos = self:find(delimiter, start, opt and opt.plain) while pos do + if opt and opt.limit and opt.limit > 0 and #result + 1 >= opt.limit then + break + end local substr = self:sub(start, pos - 1) if #substr > 0 then table.insert(result, substr) |
