modified strutils.split
This commit is contained in:
parent
4e8e5af934
commit
755d89e32d
1 changed files with 6 additions and 9 deletions
|
|
@ -374,10 +374,9 @@ iterator split*(s: string, seps: set[char] = Whitespace, maxsplit: int = -1): st
|
||||||
var first = last
|
var first = last
|
||||||
while last < len(s) and s[last] notin seps: inc(last) # BUGFIX!
|
while last < len(s) and s[last] notin seps: inc(last) # BUGFIX!
|
||||||
if first <= last-1:
|
if first <= last-1:
|
||||||
if splits == 0:
|
if splits == 0: last = len(s)
|
||||||
yield substr(s, first, len(s)-1)
|
|
||||||
break
|
|
||||||
yield substr(s, first, last-1)
|
yield substr(s, first, last-1)
|
||||||
|
if splits == 0: break
|
||||||
dec(splits)
|
dec(splits)
|
||||||
|
|
||||||
iterator split*(s: string, sep: char, maxsplit: int = -1): string =
|
iterator split*(s: string, sep: char, maxsplit: int = -1): string =
|
||||||
|
|
@ -414,10 +413,9 @@ iterator split*(s: string, sep: char, maxsplit: int = -1): string =
|
||||||
while last <= len(s):
|
while last <= len(s):
|
||||||
var first = last
|
var first = last
|
||||||
while last < len(s) and s[last] != sep: inc(last)
|
while last < len(s) and s[last] != sep: inc(last)
|
||||||
if splits == 0:
|
if splits == 0: last = len(s)
|
||||||
yield substr(s, first, len(s)-1)
|
|
||||||
break
|
|
||||||
yield substr(s, first, last-1)
|
yield substr(s, first, last-1)
|
||||||
|
if splits == 0: break
|
||||||
dec(splits)
|
dec(splits)
|
||||||
inc(last)
|
inc(last)
|
||||||
|
|
||||||
|
|
@ -432,10 +430,9 @@ iterator split*(s: string, sep: string, maxsplit: int = -1): string =
|
||||||
var first = last
|
var first = last
|
||||||
while last < len(s) and s.substr(last, last + <sep.len) != sep:
|
while last < len(s) and s.substr(last, last + <sep.len) != sep:
|
||||||
inc(last)
|
inc(last)
|
||||||
if splits == 0:
|
if splits == 0: last = len(s)
|
||||||
yield substr(s, first, len(s)-1)
|
|
||||||
break
|
|
||||||
yield substr(s, first, last-1)
|
yield substr(s, first, last-1)
|
||||||
|
if splits == 0: break
|
||||||
dec(splits)
|
dec(splits)
|
||||||
inc(last, sep.len)
|
inc(last, sep.len)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue