mirror of
https://github.com/apple/swift-collections
synced 2026-11-30 05:18:44 +00:00
More fixes.
This commit is contained in:
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)
|
||||
|
||||
Reference in new issue
Block a user