diff options
author | Joey Payne <jyapayne@gmail.com> | 2016-06-18 13:58:14 -0600 |
---|---|---|
committer | Joey Payne <jyapayne@gmail.com> | 2016-07-01 07:24:30 -0600 |
commit | 79a8a5ee72b7aca09e1dfdb03744020ebd4dae2b (patch) | |
tree | d094203a229037fbaef31a2f75bed2a7eeab2dab /lib/pure | |
parent | 890d7fac14914c9749d707be37e082af1afa9e80 (diff) | |
download | Nim-79a8a5ee72b7aca09e1dfdb03744020ebd4dae2b.tar.gz |
Add transition define for old split behavior
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/strutils.nim | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index 623ab3199..15bef1578 100644 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -26,6 +26,12 @@ include "system/inclrtl" {.pop.} +# Support old split with set[char] +when defined(nimOldSplit): + {.pragma: deprecatedSplit, deprecated.} +else: + {.pragma: deprecatedSplit.} + type CharSet* {.deprecated.} = set[char] # for compatibility with Nim {.deprecated: [TCharSet: CharSet].} @@ -376,6 +382,22 @@ template splitCommon(s, sep, maxsplit, sepLen) = dec(splits) inc(last, sepLen) +when defined(nimOldSplit): + template oldSplit(s, seps, maxsplit) = + ## Deprecated split[char] for transition period + var last = 0 + var splits = maxsplit + assert(not ('\0' in seps)) + while last < len(s): + while s[last] in seps: inc(last) + var first = last + while last < len(s) and s[last] notin seps: inc(last) # BUGFIX! + if first <= last-1: + if splits == 0: last = len(s) + yield substr(s, first, last-1) + if splits == 0: break + dec(splits) + iterator split*(s: string, seps: set[char] = Whitespace, maxsplit: int = -1): string = ## Splits the string `s` into substrings using a group of separators. @@ -418,7 +440,10 @@ iterator split*(s: string, seps: set[char] = Whitespace, ## "08" ## "08.398990" ## - splitCommon(s, seps, maxsplit, 1) + when defined(nimOldSplit): + oldSplit(s, seps, maxsplit) + else: + splitCommon(s, seps, maxsplit, 1) iterator split*(s: string, sep: char, maxsplit: int = -1): string = ## Splits the string `s` into substrings using a single separator. |