[stdlib] Rename index(...) methods to firstIndex(...)

A la SE-204.
This commit is contained in:
Nate Cook
2017-10-19 11:05:48 -05:00
parent 67852ed460
commit 58933d88c5
45 changed files with 200 additions and 175 deletions

View File

@@ -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"