mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
New indexing model: fix RNG and addition of RandomAccess to UTF16View on foundation load
This commit is contained in:
@@ -13,11 +13,24 @@
|
||||
// Random access for String.UTF16View, only when Foundation is
|
||||
// imported. Making this API dependent on Foundation decouples the
|
||||
// Swift core from a UTF16 representation.
|
||||
extension String.UTF16View.Index : RandomAccessIndex {
|
||||
extension String.UTF16View.Index : Strideable {
|
||||
/// Construct from an integer offset.
|
||||
public init(_ offset: Int) {
|
||||
_precondition(offset >= 0, "Negative UTF16 index offset not allowed")
|
||||
self.init(_offset: offset)
|
||||
// self._offset = offset
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func distance(to other: String.UTF16View.Index) -> Int {
|
||||
return other._offset.distance(to: _offset)
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func advanced(by n: Int) -> String.UTF16View.Index {
|
||||
return String.UTF16View.Index(_offset.advanced(by: n))
|
||||
}
|
||||
}
|
||||
|
||||
extension String.UTF16View : RandomAccessCollection {
|
||||
// FIXME: swift-3-indexing-model: what rules, etc. to enforce?
|
||||
}
|
||||
Reference in New Issue
Block a user