Where is this Character.init(String)
frame coming from?
Created
May 3, 2017 06:16
-
-
Save jtbandes/02c7fd125b73f621f03c5d69ac0a94d4 to your computer and use it in GitHub Desktop.
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
extension String { | |
func lazyComponents(separatedBy sep: Character) -> AnySequence<String> { | |
return AnySequence<String> { [cv = self.characters] () -> AnyIterator<String> in | |
var current = cv.startIndex | |
var finished = false | |
return AnyIterator<String> { | |
if finished { | |
return nil | |
} | |
var prev = current | |
while current < cv.endIndex && cv[current] != sep { | |
cv.formIndex(after: ¤t) | |
} | |
defer { | |
if current < cv.endIndex { | |
cv.formIndex(after: ¤t) | |
} | |
else { | |
finished = true | |
} | |
} | |
return String(cv[prev..<current]) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment