Skip to content

Commit 940f17d

Browse files
committed
Normalize indentation of switch statements.
1 parent a130dfc commit 940f17d

File tree

12 files changed

+237
-237
lines changed

12 files changed

+237
-237
lines changed

Sources/TSPL/TSPL.docc/GuidedTour/GuidedTour.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -514,14 +514,14 @@ and tests for equality.
514514
```swift
515515
let vegetable = "red pepper"
516516
switch vegetable {
517-
case "celery":
518-
print("Add some raisins and make ants on a log.")
519-
case "cucumber", "watercress":
520-
print("That would make a good tea sandwich.")
521-
case let x where x.hasSuffix("pepper"):
522-
print("Is it a spicy \(x)?")
523-
default:
524-
print("Everything tastes good in soup.")
517+
case "celery":
518+
print("Add some raisins and make ants on a log.")
519+
case "cucumber", "watercress":
520+
print("That would make a good tea sandwich.")
521+
case let x where x.hasSuffix("pepper"):
522+
print("Is it a spicy \(x)?")
523+
default:
524+
print("Everything tastes good in soup.")
525525
}
526526
// Prints "Is it a spicy red pepper?"
527527
```
@@ -1461,16 +1461,16 @@ enum Rank: Int {
14611461

14621462
func simpleDescription() -> String {
14631463
switch self {
1464-
case .ace:
1465-
return "ace"
1466-
case .jack:
1467-
return "jack"
1468-
case .queen:
1469-
return "queen"
1470-
case .king:
1471-
return "king"
1472-
default:
1473-
return String(self.rawValue)
1464+
case .ace:
1465+
return "ace"
1466+
case .jack:
1467+
return "jack"
1468+
case .queen:
1469+
return "queen"
1470+
case .king:
1471+
return "king"
1472+
default:
1473+
return String(self.rawValue)
14741474
}
14751475
}
14761476
}
@@ -1558,14 +1558,14 @@ enum Suit {
15581558

15591559
func simpleDescription() -> String {
15601560
switch self {
1561-
case .spades:
1562-
return "spades"
1563-
case .hearts:
1564-
return "hearts"
1565-
case .diamonds:
1566-
return "diamonds"
1567-
case .clubs:
1568-
return "clubs"
1561+
case .spades:
1562+
return "spades"
1563+
case .hearts:
1564+
return "hearts"
1565+
case .diamonds:
1566+
return "diamonds"
1567+
case .clubs:
1568+
return "clubs"
15691569
}
15701570
}
15711571
}
@@ -1681,10 +1681,10 @@ let success = ServerResponse.result("6:00 am", "8:09 pm")
16811681
let failure = ServerResponse.failure("Out of cheese.")
16821682

16831683
switch success {
1684-
case let .result(sunrise, sunset):
1685-
print("Sunrise is at \(sunrise) and sunset is at \(sunset).")
1686-
case let .failure(message):
1687-
print("Failure... \(message)")
1684+
case let .result(sunrise, sunset):
1685+
print("Sunrise is at \(sunrise) and sunset is at \(sunset).")
1686+
case let .failure(message):
1687+
print("Failure... \(message)")
16881688
}
16891689
// Prints "Sunrise is at 6:00 am and sunset is at 8:09 pm."
16901690
```

Sources/TSPL/TSPL.docc/LanguageGuide/ControlFlow.md

Lines changed: 80 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -796,13 +796,13 @@ one or more values of the same type.
796796

797797
```
798798
switch <#some value to consider#> {
799-
case <#value 1#>:
800-
<#respond to value 1#>
801-
case <#value 2#>,
802-
<#value 3#>:
803-
<#respond to value 2 or 3#>
804-
default:
805-
<#otherwise, do something else#>
799+
case <#value 1#>:
800+
<#respond to value 1#>
801+
case <#value 2#>,
802+
<#value 3#>:
803+
<#respond to value 2 or 3#>
804+
default:
805+
<#otherwise, do something else#>
806806
}
807807
```
808808

@@ -832,12 +832,12 @@ a single lowercase character called `someCharacter`:
832832
```swift
833833
let someCharacter: Character = "z"
834834
switch someCharacter {
835-
case "a":
836-
print("The first letter of the alphabet")
837-
case "z":
838-
print("The last letter of the alphabet")
839-
default:
840-
print("Some other character")
835+
case "a":
836+
print("The first letter of the alphabet")
837+
case "z":
838+
print("The last letter of the alphabet")
839+
default:
840+
print("Some other character")
841841
}
842842
// Prints "The last letter of the alphabet"
843843
```
@@ -891,11 +891,11 @@ It isn't valid to write the following code, because the first case is empty:
891891
```swift
892892
let anotherCharacter: Character = "a"
893893
switch anotherCharacter {
894-
case "a": // Invalid, the case has an empty body
895-
case "A":
896-
print("The letter A")
897-
default:
898-
print("Not the letter A")
894+
case "a": // Invalid, the case has an empty body
895+
case "A":
896+
print("The letter A")
897+
default:
898+
print("Not the letter A")
899899
}
900900
// This will report a compile-time error.
901901
```
@@ -936,10 +936,10 @@ separating the values with commas.
936936
```swift
937937
let anotherCharacter: Character = "a"
938938
switch anotherCharacter {
939-
case "a", "A":
940-
print("The letter A")
941-
default:
942-
print("Not the letter A")
939+
case "a", "A":
940+
print("The letter A")
941+
default:
942+
print("Not the letter A")
943943
}
944944
// Prints "The letter A"
945945
```
@@ -1050,16 +1050,16 @@ and categorizes it on the graph that follows the example.
10501050
```swift
10511051
let somePoint = (1, 1)
10521052
switch somePoint {
1053-
case (0, 0):
1054-
print("\(somePoint) is at the origin")
1055-
case (_, 0):
1056-
print("\(somePoint) is on the x-axis")
1057-
case (0, _):
1058-
print("\(somePoint) is on the y-axis")
1059-
case (-2...2, -2...2):
1060-
print("\(somePoint) is inside the box")
1061-
default:
1062-
print("\(somePoint) is outside of the box")
1053+
case (0, 0):
1054+
print("\(somePoint) is at the origin")
1055+
case (_, 0):
1056+
print("\(somePoint) is on the x-axis")
1057+
case (0, _):
1058+
print("\(somePoint) is on the y-axis")
1059+
case (-2...2, -2...2):
1060+
print("\(somePoint) is inside the box")
1061+
default:
1062+
print("\(somePoint) is outside of the box")
10631063
}
10641064
// Prints "(1, 1) is inside the box"
10651065
```
@@ -1117,12 +1117,12 @@ and categorizes it on the graph that follows:
11171117
```swift
11181118
let anotherPoint = (2, 0)
11191119
switch anotherPoint {
1120-
case (let x, 0):
1121-
print("on the x-axis with an x value of \(x)")
1122-
case (0, let y):
1123-
print("on the y-axis with a y value of \(y)")
1124-
case let (x, y):
1125-
print("somewhere else at (\(x), \(y))")
1120+
case (let x, 0):
1121+
print("on the x-axis with an x value of \(x)")
1122+
case (0, let y):
1123+
print("on the y-axis with a y value of \(y)")
1124+
case let (x, y):
1125+
print("somewhere else at (\(x), \(y))")
11261126
}
11271127
// Prints "on the x-axis with an x value of 2"
11281128
```
@@ -1182,12 +1182,12 @@ The example below categorizes an (x, y) point on the following graph:
11821182
```swift
11831183
let yetAnotherPoint = (1, -1)
11841184
switch yetAnotherPoint {
1185-
case let (x, y) where x == y:
1186-
print("(\(x), \(y)) is on the line x == y")
1187-
case let (x, y) where x == -y:
1188-
print("(\(x), \(y)) is on the line x == -y")
1189-
case let (x, y):
1190-
print("(\(x), \(y)) is just some arbitrary point")
1185+
case let (x, y) where x == y:
1186+
print("(\(x), \(y)) is on the line x == y")
1187+
case let (x, y) where x == -y:
1188+
print("(\(x), \(y)) is on the line x == -y")
1189+
case let (x, y):
1190+
print("(\(x), \(y)) is just some arbitrary point")
11911191
}
11921192
// Prints "(1, -1) is on the line x == -y"
11931193
```
@@ -1240,13 +1240,13 @@ For example:
12401240
```swift
12411241
let someCharacter: Character = "e"
12421242
switch someCharacter {
1243-
case "a", "e", "i", "o", "u":
1244-
print("\(someCharacter) is a vowel")
1245-
case "b", "c", "d", "f", "g", "h", "j", "k", "l", "m",
1246-
"n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z":
1247-
print("\(someCharacter) is a consonant")
1248-
default:
1249-
print("\(someCharacter) isn't a vowel or a consonant")
1243+
case "a", "e", "i", "o", "u":
1244+
print("\(someCharacter) is a vowel")
1245+
case "b", "c", "d", "f", "g", "h", "j", "k", "l", "m",
1246+
"n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z":
1247+
print("\(someCharacter) is a consonant")
1248+
default:
1249+
print("\(someCharacter) isn't a vowel or a consonant")
12501250
}
12511251
// Prints "e is a vowel"
12521252
```
@@ -1289,10 +1289,10 @@ and that the value always has the same type.
12891289
```swift
12901290
let stillAnotherPoint = (9, 0)
12911291
switch stillAnotherPoint {
1292-
case (let distance, 0), (0, let distance):
1293-
print("On an axis, \(distance) from the origin")
1294-
default:
1295-
print("Not on an axis")
1292+
case (let distance, 0), (0, let distance):
1293+
print("On an axis, \(distance) from the origin")
1294+
default:
1295+
print("Not on an axis")
12961296
}
12971297
// Prints "On an axis, 9 from the origin"
12981298
```
@@ -1431,16 +1431,16 @@ For brevity, multiple values are covered in a single `switch` case.
14311431
let numberSymbol: Character = "" // Chinese symbol for the number 3
14321432
var possibleIntegerValue: Int?
14331433
switch numberSymbol {
1434-
case "1", "١", "", "":
1435-
possibleIntegerValue = 1
1436-
case "2", "٢", "", "":
1437-
possibleIntegerValue = 2
1438-
case "3", "٣", "", "":
1439-
possibleIntegerValue = 3
1440-
case "4", "٤", "", "":
1441-
possibleIntegerValue = 4
1442-
default:
1443-
break
1434+
case "1", "١", "", "":
1435+
possibleIntegerValue = 1
1436+
case "2", "٢", "", "":
1437+
possibleIntegerValue = 2
1438+
case "3", "٣", "", "":
1439+
possibleIntegerValue = 3
1440+
case "4", "٤", "", "":
1441+
possibleIntegerValue = 4
1442+
default:
1443+
break
14441444
}
14451445
if let integerValue = possibleIntegerValue {
14461446
print("The integer value of \(numberSymbol) is \(integerValue).")
@@ -1520,11 +1520,11 @@ The example below uses `fallthrough` to create a textual description of a number
15201520
let integerToDescribe = 5
15211521
var description = "The number \(integerToDescribe) is"
15221522
switch integerToDescribe {
1523-
case 2, 3, 5, 7, 11, 13, 17, 19:
1524-
description += " a prime number, and also"
1525-
fallthrough
1526-
default:
1527-
description += " an integer."
1523+
case 2, 3, 5, 7, 11, 13, 17, 19:
1524+
description += " a prime number, and also"
1525+
fallthrough
1526+
default:
1527+
description += " an integer."
15281528
}
15291529
print(description)
15301530
// Prints "The number 5 is a prime number, and also an integer."
@@ -1664,16 +1664,16 @@ gameLoop: while square != finalSquare {
16641664
diceRoll += 1
16651665
if diceRoll == 7 { diceRoll = 1 }
16661666
switch square + diceRoll {
1667-
case finalSquare:
1668-
// diceRoll will move us to the final square, so the game is over
1669-
break gameLoop
1670-
case let newSquare where newSquare > finalSquare:
1671-
// diceRoll will move us beyond the final square, so roll again
1672-
continue gameLoop
1673-
default:
1674-
// this is a valid move, so find out its effect
1675-
square += diceRoll
1676-
square += board[square]
1667+
case finalSquare:
1668+
// diceRoll will move us to the final square, so the game is over
1669+
break gameLoop
1670+
case let newSquare where newSquare > finalSquare:
1671+
// diceRoll will move us beyond the final square, so roll again
1672+
continue gameLoop
1673+
default:
1674+
// this is a valid move, so find out its effect
1675+
square += diceRoll
1676+
square += board[square]
16771677
}
16781678
}
16791679
print("Game over!")

0 commit comments

Comments
 (0)