Skip to content

Commit db9f6c3

Browse files
committed
SwiftFormat pass
1 parent 82b92bc commit db9f6c3

File tree

7 files changed

+46
-31
lines changed

7 files changed

+46
-31
lines changed

Sources/SwiftASCII/ASCIICharacter.swift

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
//
22
// ASCIICharacter.swift
33
// SwiftASCII • https://github.com/orchetect/SwiftASCII
4-
// © 2022 Steffan Andrews • Licensed under MIT License
4+
// © 2021-2024 Steffan Andrews • Licensed under MIT License
55
//
66

77
import Foundation
88

99
/// ASCII Character:
1010
/// A type containing a `Character` instance that is guaranteed to conform to ASCII encoding.
11-
/// Offers a validating `exactly: Character` failable initializer and a `_ lossy: Character` conversion initializer.
11+
/// Offers a validating `exactly: Character` failable initializer and a `_ lossy: Character`
12+
/// conversion initializer.
1213
public struct ASCIICharacter: Hashable {
1314
/// The ASCII character returned as a `Character`
1415
public let characterValue: Character
@@ -32,11 +33,13 @@ public struct ASCIICharacter: Hashable {
3233
asciiValue = getASCIIValue
3334
}
3435

35-
/// Returns a new `ASCIICharacter` instance from the source character, converting a non-ASCII character to its closest ASCII equivalent if necessary.
36+
/// Returns a new `ASCIICharacter` instance from the source character, converting a non-ASCII
37+
/// character to its closest ASCII equivalent if necessary.
3638
@inlinable
3739
public init(_ lossy: Character) {
3840
guard let getASCIIValue = lossy.asciiValue else {
39-
// if ASCII encoding fails, fall back to a default character instead of throwing an exception
41+
// if ASCII encoding fails, fall back to a default character instead of throwing an
42+
// exception
4043

4144
var translated = String(lossy).asciiStringLossy
4245
if translated.stringValue.isEmpty { translated = "?" }
@@ -51,7 +54,8 @@ public struct ASCIICharacter: Hashable {
5154
asciiValue = getASCIIValue
5255
}
5356

54-
/// Returns a new `ASCIICharacter` instance if the source string contains a single character and the character is a valid ASCII character.
57+
/// Returns a new `ASCIICharacter` instance if the source string contains a single character and
58+
/// the character is a valid ASCII character.
5559
@_disfavoredOverload
5660
@inlinable
5761
public init?<S: StringProtocol>(exactly source: S) {
@@ -67,7 +71,8 @@ public struct ASCIICharacter: Hashable {
6771
asciiValue = getASCIIValue
6872
}
6973

70-
/// Returns a new `ASCIICharacter` instance if the source string contains a single character, converting a non-ASCII character to its closest ASCII equivalent if necessary.
74+
/// Returns a new `ASCIICharacter` instance if the source string contains a single character,
75+
/// converting a non-ASCII character to its closest ASCII equivalent if necessary.
7176
@inlinable
7277
public init<S: StringProtocol>(_ lossy: S) {
7378
let char: Character = lossy.first ?? "?"
@@ -76,7 +81,8 @@ public struct ASCIICharacter: Hashable {
7681
}
7782

7883
/// Returns a new `ASCIICharacter` instance if the source data is a single ASCII character.
79-
/// Returns `nil` if the source data is not a single byte or if it contains a non-ASCII character byte.
84+
/// Returns `nil` if the source data is not a single byte or if it contains a non-ASCII
85+
/// character byte.
8086
@inlinable
8187
public init?(exactly source: Data) {
8288
guard source.count == 1 else { return nil }
@@ -113,7 +119,8 @@ extension ASCIICharacter: ExpressibleByExtendedGraphemeClusterLiteral {
113119

114120
extension ASCIICharacter: CustomStringConvertible {
115121
public var description: String {
116-
// If not a printable character, return an empty string and don't allow any non-printable ASCII control characters through
122+
// If not a printable character, return an empty string and don't allow any non-printable
123+
// ASCII control characters through
117124

118125
(32 ... 126).contains(asciiValue)
119126
? String(characterValue)
@@ -234,7 +241,8 @@ extension Sequence where Element == ASCIICharacter {
234241
ASCIIString(self)
235242
}
236243

237-
/// Returns a new string by concatenating the elements of the sequence, adding the given separator between each element.
244+
/// Returns a new string by concatenating the elements of the sequence, adding the given
245+
/// separator between each element.
238246
public func joined(separator: ASCIIString) -> ASCIIString {
239247
let joinedStr = map { "\($0.characterValue)" }
240248
.joined(separator: separator.stringValue)

Sources/SwiftASCII/ASCIIString.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
//
22
// ASCIIString.swift
33
// SwiftASCII • https://github.com/orchetect/SwiftASCII
4-
// © 2022 Steffan Andrews • Licensed under MIT License
4+
// © 2021-2024 Steffan Andrews • Licensed under MIT License
55
//
66

77
import Foundation
88

99
/// ASCII String:
1010
/// A type containing a `String` instance that is guaranteed to conform to ASCII encoding.
11-
/// Offers a validating `exactly: String` failable initializer and a `_ lossy: String` conversion initializer.
11+
/// Offers a validating `exactly: String` failable initializer and a `_ lossy: String` conversion
12+
/// initializer.
1213
public struct ASCIIString: Hashable {
1314
/// The ASCII string returned as a `String`
1415
public let stringValue: String
@@ -40,13 +41,15 @@ public struct ASCIIString: Hashable {
4041
rawData = source
4142
}
4243

43-
/// Returns a new `ASCIIString` instance from the source string, removing or converting any non-ASCII characters if necessary.
44+
/// Returns a new `ASCIIString` instance from the source string, removing or converting any
45+
/// non-ASCII characters if necessary.
4446
@inlinable
4547
public init<S: StringProtocol>(_ lossy: S) {
4648
guard lossy.allSatisfy({ $0.isASCII }),
4749
let asciiData = lossy.data(using: .ascii)
4850
else {
49-
// if ASCII encoding fails, fall back to a default string instead of throwing an exception
51+
// if ASCII encoding fails, fall back to a default string instead of throwing an
52+
// exception
5053

5154
stringValue = lossy.asciiStringLossy.stringValue
5255
rawData = stringValue.data(using: .ascii) ?? Data([])
@@ -182,7 +185,8 @@ extension Sequence where Element == ASCIIString {
182185
)
183186
}
184187

185-
/// Returns a new string by concatenating the elements of the sequence, adding the given separator between each element.
188+
/// Returns a new string by concatenating the elements of the sequence, adding the given
189+
/// separator between each element.
186190
@_disfavoredOverload
187191
public func joined(separator: ASCIIString) -> ASCIIString {
188192
let joinedStr = map { $0.stringValue }
@@ -203,7 +207,7 @@ extension Sequence where Element == ASCIIString {
203207
extension ASCIIString {
204208
/// Internal use only.
205209
/// Used when string and data are already known to be valid ASCII.
206-
internal init(guaranteedASCII string: String, rawData: Data) {
210+
init(guaranteedASCII string: String, rawData: Data) {
207211
stringValue = string
208212
self.rawData = rawData
209213
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
//
22
// CharacterSet.swift
33
// SwiftASCII • https://github.com/orchetect/SwiftASCII
4-
// © 2022 Steffan Andrews • Licensed under MIT License
4+
// © 2021-2024 Steffan Andrews • Licensed under MIT License
55
//
66

77
import Foundation
88

99
extension CharacterSet {
1010
/// Includes all ASCII characters, including printable and non-printable (0...127)
11-
internal static let ascii = CharacterSet(
11+
static let ascii = CharacterSet(
1212
charactersIn: UnicodeScalar(0) ... UnicodeScalar(127)
1313
)
1414

1515
/// Includes all printable ASCII characters (32...126)
16-
internal static let asciiPrintable = CharacterSet(
16+
static let asciiPrintable = CharacterSet(
1717
charactersIn: UnicodeScalar(32) ... UnicodeScalar(126)
1818
)
1919

2020
/// Includes all ASCII characters, including printable and non-printable (0...31)
21-
internal static let asciiNonPrintable = CharacterSet(
21+
static let asciiNonPrintable = CharacterSet(
2222
charactersIn: UnicodeScalar(0) ... UnicodeScalar(31)
2323
)
2424

2525
/// Includes all extended ASCII characters (128...255)
26-
internal static let asciiExtended = CharacterSet(
26+
static let asciiExtended = CharacterSet(
2727
charactersIn: UnicodeScalar(128) ... UnicodeScalar(255)
2828
)
2929

3030
/// Includes all ASCII characters and extended characters (0...255)
31-
internal static let asciiFull = CharacterSet(
31+
static let asciiFull = CharacterSet(
3232
charactersIn: UnicodeScalar(0) ... UnicodeScalar(255)
3333
)
3434
}

Sources/SwiftASCII/String.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// String.swift
33
// SwiftASCII • https://github.com/orchetect/SwiftASCII
4-
// © 2022 Steffan Andrews • Licensed under MIT License
4+
// © 2021-2024 Steffan Andrews • Licensed under MIT License
55
//
66

77
import Foundation
@@ -36,11 +36,14 @@ extension StringProtocol {
3636

3737
/// Converts a `String` to `ASCIIString` lossily.
3838
///
39-
/// Performs a lossy conversion, transforming characters to printable ASCII substitutions where necessary.
39+
/// Performs a lossy conversion, transforming characters to printable ASCII substitutions where
40+
/// necessary.
4041
///
41-
/// Note that some characters may be transformed to representations that occupy more than one ASCII character. For example: char 189 (½) will be converted to "1/2"
42+
/// Note that some characters may be transformed to representations that occupy more than one
43+
/// ASCII character. For example: char 189 (½) will be converted to "1/2"
4244
///
43-
/// Where a suitable character substitution can't reasonably be performed, a question-mark "?" will be substituted.
45+
/// Where a suitable character substitution can't reasonably be performed, a question-mark "?"
46+
/// will be substituted.
4447
@available(OSX 10.11, iOS 9.0, *)
4548
public var asciiStringLossy: ASCIIString {
4649
let transformed = applyingTransform(

Tests/SwiftASCIITests/ASCIICharacter Tests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//
22
// ASCIICharacter Tests.swift
33
// SwiftASCII • https://github.com/orchetect/SwiftASCII
4-
// © 2022 Steffan Andrews • Licensed under MIT License
4+
// © 2021-2024 Steffan Andrews • Licensed under MIT License
55
//
66

7-
import XCTest
87
import SwiftASCII
8+
import XCTest
99

1010
class ASCIICharacterTests: XCTestCase {
1111
override func setUp() { super.setUp() }

Tests/SwiftASCIITests/ASCIIString Tests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//
22
// ASCIIString Tests.swift
33
// SwiftASCII • https://github.com/orchetect/SwiftASCII
4-
// © 2022 Steffan Andrews • Licensed under MIT License
4+
// © 2021-2024 Steffan Andrews • Licensed under MIT License
55
//
66

7-
import XCTest
87
import SwiftASCII
8+
import XCTest
99

1010
class ASCIIStringTests: XCTestCase {
1111
override func setUp() { super.setUp() }

Tests/SwiftASCIITests/String Tests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//
22
// String Tests.swift
33
// SwiftASCII • https://github.com/orchetect/SwiftASCII
4-
// © 2022 Steffan Andrews • Licensed under MIT License
4+
// © 2021-2024 Steffan Andrews • Licensed under MIT License
55
//
66

7-
import XCTest
87
import SwiftASCII
8+
import XCTest
99

1010
class StringTests: XCTestCase {
1111
override func setUp() { super.setUp() }

0 commit comments

Comments
 (0)