Make splitting an empty string give 1 empty result
This commit is contained in:
parent
6c213802f0
commit
1fe69b94c9
2 changed files with 2 additions and 2 deletions
|
|
@ -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:
|
||||||
|
|
|
||||||
|
|
@ -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", ""])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue