summary refs log tree commit diff stats
path: root/lib/impure/nre.nim
diff options
context:
space:
mode:
authorFlaviu Tamas <tamasflaviu@gmail.com>2015-06-16 20:10:32 -0400
committerFlaviu Tamas <tamasflaviu@gmail.com>2015-06-18 12:44:12 -0400
commit90292754f579efca3672970a2f5d40630936d013 (patch)
tree98b097d94366fc8ba293052838a8ac2cb53d6ec8 /lib/impure/nre.nim
parent17cace280ca927a97adc21314141947210fe17b5 (diff)
downloadNim-90292754f579efca3672970a2f5d40630936d013.tar.gz
Fix flaviut/nre#20
Diffstat (limited to 'lib/impure/nre.nim')
-rw-r--r--lib/impure/nre.nim8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/impure/nre.nim b/lib/impure/nre.nim
index 6f92b0d71..973f1f2ee 100644
--- a/lib/impure/nre.nim
+++ b/lib/impure/nre.nim
@@ -586,9 +586,12 @@ proc split*(str: string, pattern: Regex, maxSplit = -1, start = 0): seq[string]
   result = @[]
   var lastIdx = start
   var splits = 0
-  var bounds = 0 .. 0
+  var bounds = 0 .. -1
+  var never_ran = true
 
   for match in str.findIter(pattern, start = start):
+    never_ran = false
+
     # bounds are inclusive:
     #
     # 0123456
@@ -615,7 +618,8 @@ proc split*(str: string, pattern: Regex, maxSplit = -1, start = 0): seq[string]
   # "12".split("\b") would be @["1", "2", ""], but
   # if we skip an empty last match, it's the correct
   # @["1", "2"]
-  if bounds.a <= bounds.b or bounds.b < str.high:
+  # If matches were never found, then the input string is the result
+  if bounds.a <= bounds.b or bounds.b < str.high or never_ran:
     # last match: Each match takes the previous substring,
     # but "1 2".split(/ /) needs to return @["1", "2"].
     # This handles "2"