New indexing model: fix RNG and addition of RandomAccess to UTF16View on foundation load

This commit is contained in:
Shawn Erickson
2016-03-10 07:29:41 -08:00
parent 3f2f8a1d7f
commit b097b55f1a
2 changed files with 17 additions and 4 deletions

View File

@@ -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?
}