mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-12 04:09:34 +00:00
Merge pull request #9 from BlaXpirit/master
Make splitting an empty string give 1 empty result
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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", ""])
|
||||
|
||||
Reference in New Issue
Block a user