1
0
Fork 0

Fix skipping trailing empty segments in re.split

This commit is contained in:
Thomas Goyne 2014-09-20 08:13:49 -07:00
parent 9e6d5d7d9c
commit 57d66be785
2 changed files with 6 additions and 1 deletions

View File

@ -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

View File

@ -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