diff options
| author | ruki <[email protected]> | 2020-03-01 22:48:48 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-03-01 22:48:48 +0800 |
| commit | 2b41fac5b92bc0e5e3c4a848dfd7d9a1435fd20f (patch) | |
| tree | 58dabccfd6158af8a83d19f56517c40c415f5405 /xmake/core/base/string.lua | |
| parent | fc36d8022fed422d34498bc111cd69bff5b08c60 (diff) | |
improve string.split
Diffstat (limited to 'xmake/core/base/string.lua')
| -rw-r--r-- | xmake/core/base/string.lua | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/xmake/core/base/string.lua b/xmake/core/base/string.lua index 97a950bb8..e188596ce 100644 --- a/xmake/core/base/string.lua +++ b/xmake/core/base/string.lua @@ -28,6 +28,7 @@ local serialize = require("base/serialize") -- save original interfaces string._dump = string._dump or string.dump string._trim = string._trim or string.trim +string._split = string._split or string.split -- find the last substring with the given pattern function string:find_last(pattern, plain) @@ -78,13 +79,16 @@ function string:split(delimiter, opt) plain = opt.plain strict = opt.strict end + if plain then + return string._split(self, delimiter, strict, limit) + end local start = 1 local result = {} local pos, epos = self:find(delimiter, start, plain) while pos do local substr = self:sub(start, pos - 1) if (#substr > 0) or strict then - if limit and limit > 0 and #result + 1 >= imit then + if limit and limit > 0 and #result + 1 >= limit then break end table.insert(result, substr) |
