Commit 996920b4 authored by Drew's avatar Drew

Resolve a crash that can occur if a match occurs near the end of a string

parent 213bd1a5
......@@ -219,7 +219,9 @@ public class FindResultGenerator: IteratorProtocol {
public func next() -> FindResultGenerator.Element? {
let startPosition = lastStart + (lastMatch?.end ?? 0) + 1
lastStart = startPosition
let proposedStartIndex = string.utf8.index(string.utf8.startIndex, offsetBy: startPosition, limitedBy: string.utf8.endIndex)!
guard let proposedStartIndex = string.utf8.index(string.utf8.startIndex, offsetBy: startPosition, limitedBy: string.utf8.endIndex) else {
return nil //index beyond range
}
let abbreviatedString = String(string.utf8[proposedStartIndex..<string.utf8.endIndex])!
let result = try! regex.findFirst(inString: abbreviatedString)
lastMatch = result?.entireMatch
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment