mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[stdlib] Rename index(...) methods to firstIndex(...)
A la SE-204.
This commit is contained in:
@@ -52,7 +52,7 @@ extension String {
|
||||
/// using the `String` type's `init(_:)` initializer.
|
||||
///
|
||||
/// let name = "Marie Curie"
|
||||
/// if let firstSpace = name.characters.index(of: " ") {
|
||||
/// if let firstSpace = name.characters.firstIndex(of: " ") {
|
||||
/// let firstName = String(name.characters[..<firstSpace])
|
||||
/// print(firstName)
|
||||
/// }
|
||||
@@ -121,7 +121,7 @@ extension String {
|
||||
/// var str = "All this happened, more or less."
|
||||
/// let afterSpace = str.withMutableCharacters {
|
||||
/// chars -> String.CharacterView in
|
||||
/// if let i = chars.index(of: " ") {
|
||||
/// if let i = chars.firstIndex(of: " ") {
|
||||
/// let result = chars[chars.index(after: i)...]
|
||||
/// chars.removeSubrange(i...)
|
||||
/// return result
|
||||
@@ -274,7 +274,7 @@ extension String._CharacterView : BidirectionalCollection {
|
||||
/// letter and then prints the character at the found index:
|
||||
///
|
||||
/// let greeting = "Hello, friend!"
|
||||
/// if let i = greeting.characters.index(where: { "A"..."Z" ~= $0 }) {
|
||||
/// if let i = greeting.characters.firstIndex(where: { "A"..."Z" ~= $0 }) {
|
||||
/// print("First capital letter: \(greeting.characters[i])")
|
||||
/// }
|
||||
/// // Prints "First capital letter: H"
|
||||
@@ -361,7 +361,7 @@ extension String._CharacterView {
|
||||
/// not including, the first comma (`","`) in the string.
|
||||
///
|
||||
/// let str = "All this happened, more or less."
|
||||
/// let i = str.characters.index(of: ",")!
|
||||
/// let i = str.characters.firstIndex(of: ",")!
|
||||
/// let substring = str.characters[str.characters.startIndex ..< i]
|
||||
/// print(String(substring))
|
||||
/// // Prints "All this happened"
|
||||
|
||||
Reference in New Issue
Block a user