summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDenis Lisovik <cyberlis@rccraft.ru>2018-11-11 18:37:35 +0300
committerDenis Lisovik <cyberlis@rccraft.ru>2018-11-11 18:40:43 +0300
commit8b4a910c91908235e35e5fbc46f0a45df8eb459a (patch)
treea3e4d3e6241a07e1a2c3a46e6ac960c04cd93900
parentd1fe195dcc4026ee3f732bb38a0642ff6c4e0d91 (diff)
downloadNim-8b4a910c91908235e35e5fbc46f0a45df8eb459a.tar.gz
fix split proc ignored maxsplit argument. Proc split didn't pass maxsplit argument to split iterator
-rw-r--r--lib/impure/re.nim9
1 files changed, 8 insertions, 1 deletions
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
@@ -636,6 +636,11 @@ when isMainModule:
   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)
   doAssert(accum == @["AAA", "", "BBB"])
@@ -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"
#n158'>158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254