Make splitting an empty string give 1 empty result

This commit is contained in:
Oleh Prypin
2015-04-10 00:19:00 +03:00
parent 6c213802f0
commit 1fe69b94c9
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 = @[]
var lastIdx = start
var splits = 0
var bounds = 0 .. -1
var bounds = 0 .. 0
for match in str.findIter(pattern, start = start):
# 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("foo".split(re("foo")) == @["", ""])
check("".split(re"foo") == newSeq[string]())
check("".split(re"foo") == @[""])
test "captured patterns":
check("12".split(re"(\d)") == @["", "1", "", "2", ""])