Fix skipping trailing empty segments in re.split
This commit is contained in:
parent
9e6d5d7d9c
commit
57d66be785
2 changed files with 6 additions and 1 deletions
|
@ -165,7 +165,7 @@ class RegEx
|
|||
if not first or first > str\len()
|
||||
ret = str\sub prev, str\len()
|
||||
str = nil
|
||||
return ret
|
||||
return if skip_empty and ret\len() == 0 then nil else ret
|
||||
|
||||
ret = str\sub prev, first - 1
|
||||
prev = last + 1
|
||||
|
|
|
@ -170,6 +170,11 @@ describe 'split', ->
|
|||
assert.is.equal 'b', res[2]
|
||||
assert.is.equal 'c', res[3]
|
||||
|
||||
it 'should return an empty table when given only empty segments', ->
|
||||
res = re.split ',,,', ',', true
|
||||
assert.is.not.nil res
|
||||
assert.is.equal 0, #res
|
||||
|
||||
it 'should be able to split on word boundaries', ->
|
||||
res = re.split 'aa bb cc', '\\b', true
|
||||
assert.is.not.nil res
|
||||
|
|
Loading…
Reference in a new issue