@@ -15,22 +15,24 @@ import SwiftShims
15
15
/// A type that can represent a string as a collection of characters.
16
16
public protocol StringProtocol
17
17
: RangeReplaceableCollection , BidirectionalCollection ,
18
- CustomDebugStringConvertible ,
19
- CustomReflectable , CustomPlaygroundQuickLookable ,
20
18
TextOutputStream , TextOutputStreamable ,
21
19
LosslessStringConvertible , ExpressibleByStringLiteral ,
22
20
Hashable , Comparable
23
21
where Iterator. Element == Character {
24
22
25
- associatedtype UTF8Index
26
- var utf8 : String . UTF8View { get }
27
- associatedtype UTF16Index
28
- var utf16 : String . UTF16View { get }
29
- associatedtype UnicodeScalarIndex
30
- var unicodeScalars : String . UnicodeScalarView { get }
31
- /*associatedtype CharacterIndex*/
32
- var characters : String . CharacterView { get }
23
+ associatedtype UTF8View : /*Bidirectional*/Collection
24
+ where UTF8View. Element == UInt8 // Unicode.UTF8.CodeUnit
25
+
26
+ associatedtype UTF16View : BidirectionalCollection
27
+ where UTF16View. Element == UInt16 // Unicode.UTF16.CodeUnit
33
28
29
+ associatedtype UnicodeScalarView : BidirectionalCollection
30
+ where UnicodeScalarView. Element == Unicode . Scalar
31
+
32
+ var utf8 : UTF8View { get }
33
+ var utf16 : UTF16View { get }
34
+ var unicodeScalars : UnicodeScalarView { get }
35
+
34
36
#if _runtime(_ObjC)
35
37
func hasPrefix( _ prefix: String ) -> Bool
36
38
func hasSuffix( _ prefix: String ) -> Bool
@@ -110,6 +112,18 @@ public protocol StringProtocol
110
112
) rethrows -> Result
111
113
}
112
114
115
+ extension StringProtocol {
116
+ //@available(swift, deprecated: 3.2, obsoleted: 4.0, message: "Please use the StringProtocol itself")
117
+ //public var characters: Self { return self }
118
+
119
+ @available ( swift, deprecated: 3.2 , obsoleted: 4.0 , renamed: " UTF8View.Index " )
120
+ public typealias UTF8Index = UTF8View . Index
121
+ @available ( swift, deprecated: 3.2 , obsoleted: 4.0 , renamed: " UTF16View.Index " )
122
+ public typealias UTF16Index = UTF16View . Index
123
+ @available ( swift, deprecated: 3.2 , obsoleted: 4.0 , renamed: " UnicodeScalarView.Index " )
124
+ public typealias UnicodeScalarIndex = UnicodeScalarView . Index
125
+ }
126
+
113
127
/// A protocol that provides fast access to a known representation of String.
114
128
///
115
129
/// Can be used to specialize generic functions that would otherwise end up
0 commit comments