@@ -192,20 +192,19 @@ should be case-sensitive by default. We propose a standard "language" of
192192defaulted parameters to be used for these purposes, with usage roughly like this:
193193
194194``` swift
195- x.compared (to : y, case : .sensitive , in : swissGerman)
196-
197- x.lowercased (in : .currentLocale )
198-
199- x.allMatches (
200- somePattern, case : .insensitive , diacritic : .insensitive )
195+ x.compared (to : y, case : .sensitive , in : swissGerman)
196+
197+ x.lowercased (in : .currentLocale )
198+
199+ x.allMatches (somePattern, case : .insensitive , diacritic : .insensitive )
201200```
202201
203202This usage might be supported by code like this:
204203
205204``` swift
206205enum StringSensitivity {
207- case sensitive
208- case insensitive
206+ case sensitive
207+ case insensitive
209208}
210209
211210extension Locale {
@@ -301,8 +300,8 @@ an operator `<=>`:
301300enum SortOrder { case before , same , after }
302301
303302protocol Comparable : Equatable {
304- func compared (to : Self ) -> SortOrder
305- ...
303+ func compared (to : Self ) -> SortOrder
304+ ...
306305}
307306```
308307
@@ -312,8 +311,9 @@ across the library.
312311
313312``` swift
314313extension String {
315- func compared (to : Self ) -> SortOrder
316-
314+ func compared (to : Self ) -> SortOrder {
315+ ...
316+ }
317317}
318318```
319319
@@ -405,7 +405,7 @@ The benefits of restoring `Collection` conformance are substantial:
405405 "correct" this limitation by declaring a trivial conformance:
406406
407407 ``` swift
408- extension String : BidirectionalCollection {}
408+ extension String : BidirectionalCollection {}
409409 ```
410410
411411 Even if we removed indexing- by- element from `String `, users could still do
@@ -464,6 +464,7 @@ their naming:
464464
465465 * Slicing from an index to the end, or from the start to an index, is done
466466 with a method and does not support in - place mutation:
467+
467468 ```swift
468469 s.prefix (upTo : i).readOnly ()
469470 ```
@@ -684,9 +685,9 @@ the overall algorithm quadratic:
684685
685686```swift
686687extension String {
687- func containsChar (_ x : Character ) -> Bool {
688- return ! isEmpty && (first == x || dropFirst ().containsChar (x))
689- }
688+ func containsChar (_ x : Character ) -> Bool {
689+ return ! isEmpty && (first == x || dropFirst ().containsChar (x))
690+ }
690691}
691692```
692693
@@ -696,12 +697,12 @@ efficient (assuming they remember):
696697
697698```swift
698699extension String {
699- // add optional argument tracking progress through the string
700- func containsCharacter (_ x : Character , atOrAfter idx : Index ? = nil ) -> Bool {
701- let idx = idx ?? startIndex
702- return idx != endIndex
703- && (self [idx] == x || containsCharacter (x, atOrAfter : index (after : idx)))
704- }
700+ // add optional argument tracking progress through the string
701+ func containsCharacter (_ x : Character , atOrAfter idx : Index ? = nil ) -> Bool {
702+ let idx = idx ?? startIndex
703+ return idx != endIndex
704+ && (self [idx] == x || containsCharacter (x, atOrAfter : index (after : idx)))
705+ }
705706}
706707```
707708
@@ -787,9 +788,9 @@ extension Unicode {
787788
788789extension Unicode : RangeReplaceableCollection where CodeUnits :
789790 RangeReplaceableCollection {
790- // Satisfy protocol requirement
791- mutating func replaceSubrange <C : Collection >(_ : Range <Index >, with : C)
792- where C.Element == Element
791+ // Satisfy protocol requirement
792+ mutating func replaceSubrange <C : Collection >(_ : Range <Index >, with : C)
793+ where C.Element == Element
793794
794795 // ... define high-level mutating string operations, e.g. replace ...
795796}
@@ -824,7 +825,7 @@ if let firstLetter = input.dropPrefix(alphabeticCharacter) {
824825}
825826
826827if let (number, restOfInput) = input.parsingPrefix (Int .self ) {
827- ...
828+ ...
828829}
829830```
830831
@@ -871,7 +872,7 @@ the string being searched, if needed, can easily be recovered as the
871872Note also that matching operations are useful for collections in general, and
872873would fall out of this proposal:
873874
874- ```
875+ ```swift
875876// replace subsequences of contiguous NaNs with zero
876877forces.replace (oneOrMore ([Float .nan ]), [0.0 ])
877878```
0 commit comments