Skip to content

Commit 772352e

Browse files
committed
Add requirement StringProtocol.SubSequence : StringProtocol
1 parent 797df6e commit 772352e

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

stdlib/public/core/String.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public protocol StringProtocol
2121
TextOutputStream, TextOutputStreamable,
2222
LosslessStringConvertible, ExpressibleByStringLiteral,
2323
Hashable, Comparable
24-
where Iterator.Element == Character {
24+
where Iterator.Element == Character, SubSequence : StringProtocol {
2525

2626
associatedtype UTF8View : /*Bidirectional*/Collection
2727
where UTF8View.Element == UInt8 // Unicode.UTF8.CodeUnit

test/stdlib/StringCompatibility.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ extension MyString : BidirectionalCollection {
1818
typealias Iterator = String.Iterator
1919
typealias Index = String.Index
2020
typealias IndexDistance = String.IndexDistance
21+
typealias SubSequence = MyString
2122
func makeIterator() -> Iterator { return base.makeIterator() }
2223
var startIndex: String.Index { return base.startIndex }
2324
var endIndex: String.Index { return base.startIndex }
2425
subscript(i: Index) -> Character { return base[i] }
26+
subscript(indices: Range<Index>) -> MyString {
27+
return MyString(base: String(self.base[indices]))
28+
}
2529
func index(after i: Index) -> Index { return base.index(after: i) }
2630
func index(before i: Index) -> Index { return base.index(before: i) }
2731
func index(_ i: Index, offsetBy n: IndexDistance) -> Index {

0 commit comments

Comments
 (0)