mirror of
https://github.com/apple/swift-collections
synced 2026-11-25 04:37:48 +00:00
_BString.resolve: Don’t crash when resolving indices in the empty string
This commit is contained in:
2 files changed
+7
-2
No files matched your search
@@ -212,7 +212,7 @@ extension _BString {
|
||||
func resolve(_ i: Index, preferEnd: Bool) -> Index {
|
||||
if var ri = i._rope, rope.isValid(ri) {
|
||||
if preferEnd {
|
||||
guard i._utf8ChunkOffset == 0, i._utf8Offset > 0 else { return i }
|
||||
guard i._utf8Offset > 0, i._utf8ChunkOffset == 0 else { return i }
|
||||
rope.formIndex(before: &ri)
|
||||
let length = rope[ri].utf8Count
|
||||
let ci = String.Index(_utf8Offset: length)
|
||||
@@ -220,7 +220,9 @@ extension _BString {
|
||||
j._flags = i._flags
|
||||
return j
|
||||
}
|
||||
guard i._utf8ChunkOffset == rope[ri].utf8Count else { return i }
|
||||
guard i._utf8Offset < utf8Count, i._utf8ChunkOffset == rope[ri].utf8Count else {
|
||||
return i
|
||||
}
|
||||
rope.formIndex(after: &ri)
|
||||
let ci = String.Index(_utf8Offset: 0)
|
||||
var j = Index(baseUTF8Offset: i._utf8Offset, rope: ri, chunk: ci)
|
||||
|
||||
Reference in new issue
Block a user