diff options
| author | ruki <[email protected]> | 2018-01-18 00:45:46 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-01-17 22:34:39 +0800 |
| commit | 921a48f8332381d30c814419bfa05230155d342c (patch) | |
| tree | 641224c7049a9d18770f3128c96b4e80e8e1b3ba /xmake/core/base/string.lua | |
| parent | 181b4b1f01ad27978ada93e9627f76f012b0ef12 (diff) | |
add textarea
Diffstat (limited to 'xmake/core/base/string.lua')
| -rw-r--r-- | xmake/core/base/string.lua | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/xmake/core/base/string.lua b/xmake/core/base/string.lua index 5b8936360..51dfb86ef 100644 --- a/xmake/core/base/string.lua +++ b/xmake/core/base/string.lua @@ -44,12 +44,20 @@ function string:find_last(pattern, plain) end -- split string with the given characters -function string:split(chars) - - -- split it - local list = {} - self:gsub("[^" .. chars .."]+", function(v) table.insert(list, v) end ) - return list +-- +-- ("1\n\n2\n3"):split('\n') => 1, 2, 3 +-- ("1\n\n2\n3"):split('\n', true) => 1, , 2, 3 +-- +function string:split(delimiter, strict) + local result = {} + if strict then + for match in (self .. delimiter):gmatch("(.-)" .. delimiter) do + table.insert(result, match) + end + else + self:gsub("[^" .. delimiter .."]+", function(v) table.insert(result, v) end) + end + return result end -- trim the spaces |
