diff options
| -rw-r--r-- | tests/test.lua | 2 | ||||
| -rw-r--r-- | xmake/core/base/string.lua | 7 |
2 files changed, 9 insertions, 0 deletions
diff --git a/tests/test.lua b/tests/test.lua index faa7755e0..064045db9 100644 --- a/tests/test.lua +++ b/tests/test.lua @@ -22,6 +22,8 @@ end -- main entry function main(name) + assert(false, "dadasd%s", "3") + -- disable statistics os.setenv("XMAKE_STATS", "false") 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) |
