Created
August 25, 2018 18:00
-
-
Save nitely/633d3a6412c6776098d5a1ec3af073c3 to your computer and use it in GitHub Desktop.
nim-regex find based split
This file contains 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
proc split*(s: string, sep: Regex): seq[string] = | |
result = @[] | |
var | |
m = RegexMatch() | |
ds = initDataSets(sep.states.len, true) | |
first = 0 | |
last = 0 | |
n = 0 | |
while last <= s.len: | |
first = last | |
if findImpl(ds, s, sep, m, last) and | |
m.boundaries.a <= m.boundaries.b: | |
n = m.boundaries.b+1 | |
last = m.boundaries.a | |
else: | |
n = s.len+1 | |
last = s.len+1 | |
result.add(substr(s, first, last-1)) | |
if n > 0: | |
last = n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment