Last active
January 3, 2016 22:19
-
-
Save Varriount/8527495 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import strutils | |
type charContainer = generic c | |
c.contains(char) is bool | |
iterator split*(s: string, seps: charContainer = Whitespace): string = | |
## Splits the string `s` into substrings using a group of separators. | |
## | |
## Substrings are separated by a substring containing only `seps`. Note | |
## that whole sequences of characters found in ``seps`` will be counted as | |
## a single split point and leading/trailing separators will be ignored. | |
var last = 0 | |
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: | |
yield substr(s, first, last-1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment