Merge pull request #9 from BlaXpirit/master

Make splitting an empty string give 1 empty result
This commit is contained in:
Flaviu Tamas 2015-04-09 17:23:03 -04:00
commit a665279192
2 changed files with 2 additions and 2 deletions

View file

@ -387,7 +387,7 @@ proc split*(str: string, pattern: Regex, maxSplit = -1, start = 0): seq[string]
result = @[] result = @[]
var lastIdx = start var lastIdx = start
var splits = 0 var splits = 0
var bounds = 0 .. -1 var bounds = 0 .. 0
for match in str.findIter(pattern, start = start): for match in str.findIter(pattern, start = start):
# bounds are inclusive: # bounds are inclusive:

View file

@ -7,7 +7,7 @@ suite "string splitting":
check("1 2 ".split(re(" ")) == @["1", "", "2", "", ""]) check("1 2 ".split(re(" ")) == @["1", "", "2", "", ""])
check("1 2".split(re(" ")) == @["1", "2"]) check("1 2".split(re(" ")) == @["1", "2"])
check("foo".split(re("foo")) == @["", ""]) check("foo".split(re("foo")) == @["", ""])
check("".split(re"foo") == newSeq[string]()) check("".split(re"foo") == @[""])
test "captured patterns": test "captured patterns":
check("12".split(re"(\d)") == @["", "1", "", "2", ""]) check("12".split(re"(\d)") == @["", "1", "", "2", ""])