mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[stdlib] Rename index(...) methods to firstIndex(...)
A la SE-204.
This commit is contained in:
@@ -55,7 +55,7 @@ extension String {
|
||||
/// `String` type's `init(_:)` initializer.
|
||||
///
|
||||
/// let favemoji = "My favorite emoji is 🎉"
|
||||
/// if let i = favemoji.utf16.index(where: { $0 >= 128 }) {
|
||||
/// if let i = favemoji.utf16.firstIndex(where: { $0 >= 128 }) {
|
||||
/// let asciiPrefix = String(favemoji.utf16[..<i])
|
||||
/// print(asciiPrefix)
|
||||
/// }
|
||||
@@ -303,7 +303,7 @@ extension String {
|
||||
/// another string's `utf16` view.
|
||||
///
|
||||
/// let picnicGuest = "Deserving porcupine"
|
||||
/// if let i = picnicGuest.utf16.index(of: 32) {
|
||||
/// if let i = picnicGuest.utf16.firstIndex(of: 32) {
|
||||
/// let adjective = String(picnicGuest.utf16[..<i])
|
||||
/// print(adjective)
|
||||
/// }
|
||||
@@ -379,7 +379,7 @@ extension String.UTF16View.Index {
|
||||
///
|
||||
/// let cafe = "Café 🍵"
|
||||
///
|
||||
/// let stringIndex = cafe.index(of: "é")!
|
||||
/// let stringIndex = cafe.firstIndex(of: "é")!
|
||||
/// let utf16Index = String.Index(stringIndex, within: cafe.utf16)!
|
||||
///
|
||||
/// print(cafe.utf16[...utf16Index])
|
||||
@@ -407,7 +407,7 @@ extension String.UTF16View.Index {
|
||||
/// position in the string's `unicodeScalars` view.
|
||||
///
|
||||
/// let cafe = "Café 🍵"
|
||||
/// let i = cafe.utf16.index(of: 32)!
|
||||
/// let i = cafe.utf16.firstIndex(of: 32)!
|
||||
/// let j = i.samePosition(in: cafe.unicodeScalars)!
|
||||
/// print(cafe.unicodeScalars[..<j])
|
||||
/// // Prints "Café"
|
||||
|
||||
Reference in New Issue
Block a user