summary refs log tree commit diff stats
path: root/src/nre.nim
diff options
context:
space:
mode:
authorFlaviu Tamas <tamasflaviu@gmail.com>2015-01-24 14:58:09 -0500
committerFlaviu Tamas <tamasflaviu@gmail.com>2015-01-24 14:58:09 -0500
commite027ea91395b27849c4b8db11555a263ea894b76 (patch)
tree59579893d8b6faef049d0bbc2b66eb4ca800b8ab /src/nre.nim
parentba3aac1b13d73e515dfed50376d82f57a46d7d2c (diff)
downloadNim-e027ea91395b27849c4b8db11555a263ea894b76.tar.gz
Add start to split
Diffstat (limited to 'src/nre.nim')
-rw-r--r--src/nre.nim8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/nre.nim b/src/nre.nim
index 47e374978..6743a82dc 100644
--- a/src/nre.nim
+++ b/src/nre.nim
@@ -384,13 +384,13 @@ proc renderBounds(str: string, bounds: Slice[int]): string =
   for i in bounds.a .. bounds.b:
     result.add("^")
 
-proc split*(str: string, pattern: Regex, maxSplit = -1): seq[string] =
+proc split*(str: string, pattern: Regex, maxSplit = -1, start = 0): seq[string] =
   result = @[]
-  var lastIdx = 0
+  var lastIdx = start
   var splits = 0
   var bounds: Slice[int]
 
-  for match in str.findIter(pattern):
+  for match in str.findIter(pattern, start = start):
     # upper bound is exclusive, lower is inclusive:
     #
     # 0123456
@@ -401,7 +401,7 @@ proc split*(str: string, pattern: Regex, maxSplit = -1): seq[string] =
     # "12".split("") would be @["", "1", "2"], but
     # if we skip an empty first match, it's the correct
     # @["1", "2"]
-    if bounds.a < bounds.b or bounds.a > 0:
+    if bounds.a < bounds.b or bounds.a > start:
       result.add(str.substr(lastIdx, bounds.a - 1))
       splits += 1