From 1fe69b94c9bc4ace9b4f0a6c105ffd4d12b877b9 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Fri, 10 Apr 2015 00:19:00 +0300 Subject: [PATCH] Make splitting an empty string give 1 empty result --- src/nre.nim | 2 +- test/split.nim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nre.nim b/src/nre.nim index af5dab785f..f9c6b3509a 100644 --- a/src/nre.nim +++ b/src/nre.nim @@ -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: diff --git a/test/split.nim b/test/split.nim index 62b88427b2..0f4e8d24a8 100644 --- a/test/split.nim +++ b/test/split.nim @@ -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", ""])