Make sure we don't use negative oftsets when finding an index. Fixes #3204

This commit is contained in:
Maurice Parker 2021-06-26 20:54:17 -05:00
parent b549293167
commit 100823e57e
1 changed files with 2 additions and 2 deletions

View File

@ -91,8 +91,8 @@ private extension TwitterStatus {
}
}
let offsetStartIndex = entity.startIndex - unicodeScalarOffset
let offsetEndIndex = entity.endIndex - unicodeScalarOffset
let offsetStartIndex = unicodeScalarOffset < entity.startIndex ? entity.startIndex - unicodeScalarOffset : entity.startIndex
let offsetEndIndex = unicodeScalarOffset < entity.endIndex ? entity.endIndex - unicodeScalarOffset : entity.endIndex
let entityStartIndex = text.index(text.startIndex, offsetBy: offsetStartIndex, limitedBy: text.endIndex) ?? text.startIndex
let entityEndIndex = text.index(text.startIndex, offsetBy: offsetEndIndex, limitedBy: text.endIndex) ?? text.endIndex