Skip to content

Commit 3247fbc

Browse files
authored
Merge pull request #9578 from natecook1000/swift-4.0-branch
2 parents 59a2644 + 6ca22c7 commit 3247fbc

25 files changed

+1044
-587
lines changed

stdlib/public/SDK/Foundation/NSStringAPI.swift

Lines changed: 149 additions & 78 deletions
Large diffs are not rendered by default.

stdlib/public/core/Arrays.swift.gyb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ if True:
9595
///
9696
/// let midpoint = absences.count / 2
9797
///
98-
/// let firstHalf = absences.prefix(upTo: midpoint)
99-
/// let secondHalf = absences.suffix(from: midpoint)
98+
/// let firstHalf = absences[..<midpoint]
99+
/// let secondHalf = absences[midpoint...]
100100
///
101101
/// Neither the `firstHalf` nor `secondHalf` slices allocate any new storage
102102
/// of their own. Instead, each presents a view onto the storage of the
@@ -151,7 +151,7 @@ if True:
151151
/// Here's an implementation of those steps:
152152
///
153153
/// if let i = absences.index(where: { $0 > 0 }) { // 1
154-
/// let absencesAfterFirst = absences.suffix(from: i + 1) // 2
154+
/// let absencesAfterFirst = absences[(i + 1)...] // 2
155155
/// if let j = absencesAfterFirst.index(where: { $0 > 0 }) { // 3
156156
/// print("The first day with absences had \(absences[i]).") // 4
157157
/// print("The second day with absences had \(absences[j]).")

stdlib/public/core/Bool.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ extension Bool {
202202
}
203203

204204
extension Bool {
205-
/// Performs a logical AND operation on two Bool values.
205+
/// Performs a logical AND operation on two Boolean values.
206206
///
207-
/// The logical AND operator (`&&`) combines two Bool values and returns
207+
/// The logical AND operator (`&&`) combines two Boolean values and returns
208208
/// `true` if both of the values are `true`. If either of the values is
209209
/// `false`, the operator returns `false`.
210210
///
@@ -241,9 +241,9 @@ extension Bool {
241241
return lhs ? try rhs() : false
242242
}
243243

244-
/// Performs a logical OR operation on two Bool values.
244+
/// Performs a logical OR operation on two Boolean values.
245245
///
246-
/// The logical OR operator (`||`) combines two Bool values and returns
246+
/// The logical OR operator (`||`) combines two Boolean values and returns
247247
/// `true` if at least one of the values is `true`. If both values are
248248
/// `false`, the operator returns `false`.
249249
///

stdlib/public/core/Builtin.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -817,12 +817,13 @@ public func type<T, Metatype>(of value: T) -> Metatype {
817817
/// behavior for the escapable closure to be stored, referenced, or executed
818818
/// after the function returns.
819819
///
820-
/// - Parameter closure: A non-escaping closure value that will be made
821-
/// escapable for the duration of the execution of the `body` closure. If
822-
/// `body` has a return value, it is used as the return value for the
823-
/// `withoutActuallyEscaping(_:do:)` function.
824-
/// - Parameter body: A closure that will be immediately executed, receiving an
825-
/// escapable copy of `closure` as an argument.
820+
/// - Parameters:
821+
/// - closure: A non-escaping closure value that will be made escapable for
822+
/// the duration of the execution of the `body` closure. If `body` has a
823+
/// return value, it is used as the return value for the
824+
/// `withoutActuallyEscaping(_:do:)` function.
825+
/// - body: A closure that will be immediately executed, receiving an
826+
/// escapable copy of `closure` as an argument.
826827
/// - Returns: The return value of the `body` closure, if any.
827828
@_transparent
828829
@_semantics("typechecker.withoutActuallyEscaping(_:do:)")

stdlib/public/core/Character.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
/// The `Character` type represents a character made up of one or more Unicode
1717
/// scalar values, grouped by a Unicode boundary algorithm. Generally, a
1818
/// `Character` instance matches what the reader of a string will perceive as
19-
/// a single character. The number of visible characters is generally the most
20-
/// natural way to count the length of a string.
19+
/// a single character. Strings are collections of `Character` instances, so
20+
/// the number of visible characters is generally the most natural way to
21+
/// count the length of a string.
2122
///
2223
/// let greeting = "Hello! 🐥"
23-
/// print("Character count: \(greeting.characters.count)")
24-
/// // Prints "Character count: 8"
24+
/// print("Length: \(greeting.count)")
25+
/// // Prints "Length: 8"
2526
///
2627
/// Because each character in a string can be made up of one or more Unicode
2728
/// code points, the number of characters in a string may not match the length

stdlib/public/core/Collection.swift

Lines changed: 89 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -448,21 +448,20 @@ public struct IndexingIterator<
448448
/// at a specific position when using a collection.
449449
///
450450
/// For example, if you want to print only the first word in a string, search
451-
/// for the index of the first space and then create a subsequence up to that
451+
/// for the index of the first space, and then create a subsequence up to that
452452
/// position.
453453
///
454454
/// let text = "Buffalo buffalo buffalo buffalo."
455-
/// if let firstSpace = text.characters.index(of: " ") {
456-
/// print(String(text.characters.prefix(upTo: firstSpace)))
455+
/// if let firstSpace = text.index(of: " ") {
456+
/// print(text[..<firstSpace])
457457
/// }
458458
/// // Prints "Buffalo"
459459
///
460-
/// The `firstSpace` constant is an index into the `text.characters`
461-
/// collection. `firstSpace` is the position of the first space in the
462-
/// collection. You can store indices in variables, and pass them to
463-
/// collection algorithms or use them later to access the corresponding
464-
/// element. In the example above, `firstSpace` is used to extract the prefix
465-
/// that contains elements up to that index.
460+
/// The `firstSpace` constant is an index into the `text` string---the position
461+
/// of the first space in the string. You can store indices in variables, and
462+
/// pass them to collection algorithms or use them later to access the
463+
/// corresponding element. In the example above, `firstSpace` is used to
464+
/// extract the prefix that contains elements up to that index.
466465
///
467466
/// You can pass only valid indices to collection operations. You can find a
468467
/// complete set of a collection's valid indices by starting with the
@@ -486,7 +485,7 @@ public struct IndexingIterator<
486485
/// Here's an example of accessing the first character in a string through its
487486
/// subscript:
488487
///
489-
/// let firstChar = text.characters[text.characters.startIndex]
488+
/// let firstChar = text[text.startIndex]
490489
/// print(firstChar)
491490
/// // Prints "B"
492491
///
@@ -496,40 +495,33 @@ public struct IndexingIterator<
496495
/// using the `first` property, which has the value of the first element of
497496
/// the collection, or `nil` if the collection is empty.
498497
///
499-
/// print(text.characters.first)
498+
/// print(text.first)
500499
/// // Prints "Optional("B")"
501500
///
502501
/// Accessing Slices of a Collection
503502
/// ================================
504503
///
505504
/// You can access a slice of a collection through its ranged subscript or by
506-
/// calling methods like `prefix(_:)` or `suffix(from:)`. A slice of a
505+
/// calling methods like `prefix(while:)` or `suffix(_:)`. A slice of a
507506
/// collection can contain zero or more of the original collection's elements
508507
/// and shares the original collection's semantics.
509508
///
510-
/// The following example, creates a `firstWord` constant by using the
511-
/// `prefix(_:)` method to get a slice of the `text` string's `characters`
512-
/// view.
509+
/// The following example creates a `firstWord` constant by using the
510+
/// `prefix(where:)` method to get a slice of the `text` string.
513511
///
514-
/// let firstWord = text.characters.prefix(7)
515-
/// print(String(firstWord))
512+
/// let firstWord = text.prefix(while: { $0 != " " })
513+
/// print(firstWord)
516514
/// // Prints "Buffalo"
517515
///
518-
/// You can retrieve the same slice using other methods, such as finding the
519-
/// terminating index, and then using the `prefix(upTo:)` method, which takes
520-
/// an index as its parameter, or by using the view's ranged subscript.
516+
/// You can retrieve the same slice using the string's ranged subscript, which
517+
/// takes a range expression.
521518
///
522-
/// if let firstSpace = text.characters.index(of: " ") {
523-
/// print(text.characters.prefix(upTo: firstSpace))
524-
/// // Prints "Buffalo"
525-
///
526-
/// let start = text.characters.startIndex
527-
/// print(text.characters[start..<firstSpace])
519+
/// if let firstSpace = text.index(of: " ") {
520+
/// print(text[..<firstSpace]
528521
/// // Prints "Buffalo"
529522
/// }
530523
///
531-
/// The retrieved slice of `text.characters` is equivalent in each of these
532-
/// cases.
524+
/// The retrieved slice of `text` is equivalent in each of these cases.
533525
///
534526
/// Slices Share Indices
535527
/// --------------------
@@ -567,10 +559,9 @@ public struct IndexingIterator<
567559
/// -----------------------------------
568560
///
569561
/// A slice inherits the value or reference semantics of its base collection.
570-
/// That is, when working with a slice of a mutable
571-
/// collection that has value semantics, such as an array, mutating the
572-
/// original collection triggers a copy of that collection, and does not
573-
/// affect the contents of the slice.
562+
/// That is, when working with a slice of a mutable collection that has value
563+
/// semantics, such as an array, mutating the original collection triggers a
564+
/// copy of that collection, and does not affect the contents of the slice.
574565
///
575566
/// For example, if you update the last element of the `absences` array from
576567
/// `0` to `2`, the `secondHalf` slice is unchanged.
@@ -598,7 +589,7 @@ public struct IndexingIterator<
598589
/// indices or the view itself is being iterated.
599590
///
600591
/// let word = "Swift"
601-
/// for character in word.characters {
592+
/// for character in word {
602593
/// print(character)
603594
/// }
604595
/// // Prints "S"
@@ -607,8 +598,8 @@ public struct IndexingIterator<
607598
/// // Prints "f"
608599
/// // Prints "t"
609600
///
610-
/// for i in word.characters.indices {
611-
/// print(word.characters[i])
601+
/// for i in word.indices {
602+
/// print(word[i])
612603
/// }
613604
/// // Prints "S"
614605
/// // Prints "w"
@@ -798,6 +789,15 @@ public protocol Collection : _Indexable, Sequence
798789
/// print(numbers.prefix(upTo: numbers.startIndex))
799790
/// // Prints "[]"
800791
///
792+
/// Using the `prefix(upTo:)` method is equivalent to using a partial
793+
/// half-open range as the collection's subscript. The subscript notation is
794+
/// preferred over `prefix(upTo:)`.
795+
///
796+
/// if let i = numbers.index(of: 40) {
797+
/// print(numbers[..<i])
798+
/// }
799+
/// // Prints "[10, 20, 30]"
800+
///
801801
/// - Parameter end: The "past the end" index of the resulting subsequence.
802802
/// `end` must be a valid index of the collection.
803803
/// - Returns: A subsequence up to, but not including, the `end` position.
@@ -825,6 +825,15 @@ public protocol Collection : _Indexable, Sequence
825825
/// print(numbers.suffix(from: numbers.endIndex))
826826
/// // Prints "[]"
827827
///
828+
/// Using the `suffix(from:)` method is equivalent to using a partial range
829+
/// from the index as the collection's subscript. The subscript notation is
830+
/// preferred over `suffix(from:)`.
831+
///
832+
/// if let i = numbers.index(of: 40) {
833+
/// print(numbers[i...])
834+
/// }
835+
/// // Prints "[40, 50, 60]"
836+
///
828837
/// - Parameter start: The index at which to start the resulting subsequence.
829838
/// `start` must be a valid index of the collection.
830839
/// - Returns: A subsequence starting at the `start` position.
@@ -846,6 +855,15 @@ public protocol Collection : _Indexable, Sequence
846855
/// }
847856
/// // Prints "[10, 20, 30, 40]"
848857
///
858+
/// Using the `prefix(through:)` method is equivalent to using a partial
859+
/// closed range as the collection's subscript. The subscript notation is
860+
/// preferred over `prefix(through:)`.
861+
///
862+
/// if let i = numbers.index(of: 40) {
863+
/// print(numbers[...i])
864+
/// }
865+
/// // Prints "[10, 20, 30, 40]"
866+
///
849867
/// - Parameter end: The index of the last element to include in the
850868
/// resulting subsequence. `end` must be a valid index of the collection
851869
/// that is not equal to the `endIndex` property.
@@ -864,7 +882,7 @@ public protocol Collection : _Indexable, Sequence
864882
/// through the elements of the collection.
865883
///
866884
/// let horseName = "Silver"
867-
/// if horseName.characters.isEmpty {
885+
/// if horseName.isEmpty {
868886
/// print("I've been through the desert on a horse with no name.")
869887
/// } else {
870888
/// print("Hi ho, \(horseName)!")
@@ -1319,7 +1337,7 @@ extension Collection {
13191337
/// through the elements of the collection.
13201338
///
13211339
/// let horseName = "Silver"
1322-
/// if horseName.characters.isEmpty {
1340+
/// if horseName.isEmpty {
13231341
/// print("I've been through the desert on a horse with no name.")
13241342
/// } else {
13251343
/// print("Hi ho, \(horseName)!")
@@ -1420,7 +1438,7 @@ extension Collection {
14201438
/// let cast = ["Vivien", "Marlon", "Kim", "Karl"]
14211439
/// let lowercaseNames = cast.map { $0.lowercaseString }
14221440
/// // 'lowercaseNames' == ["vivien", "marlon", "kim", "karl"]
1423-
/// let letterCounts = cast.map { $0.characters.count }
1441+
/// let letterCounts = cast.map { $0.count }
14241442
/// // 'letterCounts' == [6, 6, 3, 4]
14251443
///
14261444
/// - Parameter transform: A mapping closure. `transform` accepts an
@@ -1622,6 +1640,15 @@ extension Collection {
16221640
/// print(numbers.prefix(upTo: numbers.startIndex))
16231641
/// // Prints "[]"
16241642
///
1643+
/// Using the `prefix(upTo:)` method is equivalent to using a partial
1644+
/// half-open range as the collection's subscript. The subscript notation is
1645+
/// preferred over `prefix(upTo:)`.
1646+
///
1647+
/// if let i = numbers.index(of: 40) {
1648+
/// print(numbers[..<i])
1649+
/// }
1650+
/// // Prints "[10, 20, 30]"
1651+
///
16251652
/// - Parameter end: The "past the end" index of the resulting subsequence.
16261653
/// `end` must be a valid index of the collection.
16271654
/// - Returns: A subsequence up to, but not including, the `end` position.
@@ -1652,6 +1679,15 @@ extension Collection {
16521679
/// print(numbers.suffix(from: numbers.endIndex))
16531680
/// // Prints "[]"
16541681
///
1682+
/// Using the `suffix(from:)` method is equivalent to using a partial range
1683+
/// from the index as the collection's subscript. The subscript notation is
1684+
/// preferred over `suffix(from:)`.
1685+
///
1686+
/// if let i = numbers.index(of: 40) {
1687+
/// print(numbers[i...])
1688+
/// }
1689+
/// // Prints "[40, 50, 60]"
1690+
///
16551691
/// - Parameter start: The index at which to start the resulting subsequence.
16561692
/// `start` must be a valid index of the collection.
16571693
/// - Returns: A subsequence starting at the `start` position.
@@ -1676,6 +1712,15 @@ extension Collection {
16761712
/// }
16771713
/// // Prints "[10, 20, 30, 40]"
16781714
///
1715+
/// Using the `prefix(through:)` method is equivalent to using a partial
1716+
/// closed range as the collection's subscript. The subscript notation is
1717+
/// preferred over `prefix(through:)`.
1718+
///
1719+
/// if let i = numbers.index(of: 40) {
1720+
/// print(numbers[...i])
1721+
/// }
1722+
/// // Prints "[10, 20, 30, 40]"
1723+
///
16791724
/// - Parameter end: The index of the last element to include in the
16801725
/// resulting subsequence. `end` must be a valid index of the collection
16811726
/// that is not equal to the `endIndex` property.
@@ -1701,25 +1746,20 @@ extension Collection {
17011746
/// that was originally separated by one or more spaces.
17021747
///
17031748
/// let line = "BLANCHE: I don't want realism. I want magic!"
1704-
/// print(line.characters.split(whereSeparator: { $0 == " " })
1705-
/// .map(String.init))
1749+
/// print(line.split(whereSeparator: { $0 == " " }))
17061750
/// // Prints "["BLANCHE:", "I", "don\'t", "want", "realism.", "I", "want", "magic!"]"
17071751
///
17081752
/// The second example passes `1` for the `maxSplits` parameter, so the
17091753
/// original string is split just once, into two new strings.
17101754
///
1711-
/// print(
1712-
/// line.characters.split(
1713-
/// maxSplits: 1, whereSeparator: { $0 == " " }
1714-
/// ).map(String.init))
1755+
/// print(line.split(maxSplits: 1, whereSeparator: { $0 == " " }))
17151756
/// // Prints "["BLANCHE:", " I don\'t want realism. I want magic!"]"
17161757
///
17171758
/// The final example passes `false` for the `omittingEmptySubsequences`
17181759
/// parameter, so the returned array contains empty strings where spaces
17191760
/// were repeated.
17201761
///
1721-
/// print(line.characters.split(omittingEmptySubsequences: false, whereSeparator: { $0 == " " })
1722-
/// .map(String.init))
1762+
/// print(line.split(omittingEmptySubsequences: false, whereSeparator: { $0 == " " }))
17231763
/// // Prints "["BLANCHE:", "", "", "I", "don\'t", "want", "realism.", "I", "want", "magic!"]"
17241764
///
17251765
/// - Parameters:
@@ -1801,23 +1841,20 @@ extension Collection where Iterator.Element : Equatable {
18011841
/// was originally separated by one or more spaces.
18021842
///
18031843
/// let line = "BLANCHE: I don't want realism. I want magic!"
1804-
/// print(line.characters.split(separator: " ")
1805-
/// .map(String.init))
1844+
/// print(line.split(separator: " "))
18061845
/// // Prints "["BLANCHE:", "I", "don\'t", "want", "realism.", "I", "want", "magic!"]"
18071846
///
18081847
/// The second example passes `1` for the `maxSplits` parameter, so the
18091848
/// original string is split just once, into two new strings.
18101849
///
1811-
/// print(line.characters.split(separator: " ", maxSplits: 1)
1812-
/// .map(String.init))
1850+
/// print(line.split(separator: " ", maxSplits: 1))
18131851
/// // Prints "["BLANCHE:", " I don\'t want realism. I want magic!"]"
18141852
///
18151853
/// The final example passes `false` for the `omittingEmptySubsequences`
18161854
/// parameter, so the returned array contains empty strings where spaces
18171855
/// were repeated.
18181856
///
1819-
/// print(line.characters.split(separator: " ", omittingEmptySubsequences: false)
1820-
/// .map(String.init))
1857+
/// print(line.split(separator: " ", omittingEmptySubsequences: false))
18211858
/// // Prints "["BLANCHE:", "", "", "I", "don\'t", "want", "realism.", "I", "want", "magic!"]"
18221859
///
18231860
/// - Parameters:

0 commit comments

Comments
 (0)