mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[String.Index] Simplify and prepare for more resilience.
Simplify String.Index by sinking transcoded offsets into the .utf8 variant. This is in preparation for a more resilient index type capable of supporting existential string indices.
This commit is contained in:
@@ -221,18 +221,18 @@ extension String._CharacterView : BidirectionalCollection {
|
||||
/// this view's `_baseOffset`.
|
||||
@inlinable // FIXME(sil-serialize-all)
|
||||
internal func _toBaseIndex(_ index: Index) -> Index {
|
||||
return Index(
|
||||
encodedOffset: index.encodedOffset - _baseOffset,
|
||||
index._cache)
|
||||
var ret = index
|
||||
ret._codeUnitOffset -= _baseOffset
|
||||
return ret
|
||||
}
|
||||
|
||||
/// Translates an index in the underlying base string into a view index using
|
||||
/// this view's `_baseOffset`.
|
||||
@inlinable // FIXME(sil-serialize-all)
|
||||
internal func _toViewIndex(_ index: Index) -> Index {
|
||||
return Index(
|
||||
encodedOffset: index.encodedOffset + _baseOffset,
|
||||
index._cache)
|
||||
var ret = index
|
||||
ret._codeUnitOffset += _baseOffset
|
||||
return ret
|
||||
}
|
||||
|
||||
/// The position of the first character in a nonempty character view.
|
||||
|
||||
Reference in New Issue
Block a user