From 8b4a910c91908235e35e5fbc46f0a45df8eb459a Mon Sep 17 00:00:00 2001
From: Denis Lisovik <cyberlis@rccraft.ru>
Date: Sun, 11 Nov 2018 18:37:35 +0300
Subject: fix split proc ignored maxsplit argument. Proc split didn't pass
 maxsplit argument to split iterator

---
 lib/impure/re.nim | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

(limited to 'lib/impure/re.nim')

diff --git a/lib/impure/re.nim b/lib/impure/re.nim
index b142f58cd..dc4ee326f 100644
--- a/lib/impure/re.nim
+++ b/lib/impure/re.nim
@@ -547,7 +547,7 @@ proc split*(s: string, sep: Regex, maxsplit = -1): seq[string] {.inline.} =
   ##
   ## The portion matched by ``sep`` is not returned.
   result = @[]
-  for x in split(s, sep): result.add x
+  for x in split(s, sep, maxsplit): result.add x
 
 proc escapeRe*(s: string): string =
   ## escapes ``s`` so that it is matched verbatim when used as a regular
@@ -635,6 +635,11 @@ when isMainModule:
     accum.add(word)
   doAssert(accum == @["", "this", "is", "an", "example", ""])
 
+  accum = @[]
+  for word in split("00232this02939is39an22example111", re"\d+", maxsplit=2):
+    accum.add(word)
+  doAssert(accum == @["", "this", "is39an22example111"])
+
   accum = @[]
   for word in split("AAA :   : BBB", re"\s*:\s*"):
     accum.add(word)
@@ -647,6 +652,8 @@ when isMainModule:
   doAssert(split(";a;b;c", re";") == @["", "a", "b", "c"])
   doAssert(split(";a;b;c;", re";") == @["", "a", "b", "c", ""])
   doAssert(split("a;b;c;", re";") == @["a", "b", "c", ""])
+  doAssert(split("00232this02939is39an22example111", re"\d+", maxsplit=2) == @["", "this", "is39an22example111"])
+
 
   for x in findAll("abcdef", re"^{.}", 3):
     doAssert x == "d"
-- 
cgit 1.4.1-2-gfad0