More fixes.

This commit is contained in:
Karoy Lorentey committed 2023-03-20 13:12:10 -07:00
1 parent 605e45b9b9
commit fe54fdaa47
3 files changed
+9 -4

No files matched your search

@@ -154,6 +154,10 @@ extension _BString {
in metric: some _StringMetric
) -> Index {
precondition(i <= endIndex, "Index out of bounds")
if isEmpty {
precondition(distance == 0, "Index out of bounds")
return startIndex
}
let i = resolve(i, preferEnd: i == endIndex || distance < 0)
var ri = i._rope!
var ci = i._chunkIndex
@@ -265,7 +269,7 @@ extension _BString {
let i = resolve(i, preferEnd: false)
let ri = i._rope!
var ci = i._chunkIndex
var chunk = rope[ri]
let chunk = rope[ri]
chunk.string.utf8.formIndex(after: &ci)
if ci == chunk.string.endIndex {
return Index(
@@ -360,9 +364,10 @@ extension _BString {
func utf8Index(roundingDown i: Index) -> Index {
precondition(i <= endIndex, "Index out of bounds")
guard i < endIndex else { return endIndex }
var r = i
r._clearUTF16TrailingSurrogate()
return r
return resolve(r, preferEnd: false)
}
func utf16Index(roundingDown i: Index) -> Index {
@@ -151,7 +151,7 @@ extension _BString {
func resolve(_ i: Index, preferEnd: Bool) -> Index {
if var ri = i._rope, rope.isValid(ri) {
if preferEnd {
guard i._utf8ChunkOffset == 0 else { return i }
guard i._utf8ChunkOffset == 0, i._utf8Offset > 0 else { return i }
rope.formIndex(before: &ri)
let length = rope[ri].utf8Count
let ci = String.Index(_utf8Offset: length)