Skip to content

Commit 6a6385a

Browse files
committed
Use 2 spaces for indentation
1 parent 14f9a32 commit 6a6385a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+7584
-7584
lines changed

CodableCSV.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Pod::Spec.new do |s|
1212
s.osx.deployment_target = "10.10"
1313
s.watchos.deployment_target = "2.0"
1414
s.tvos.deployment_target = "9.0"
15-
s.swift_version = ["5.1", "5.2", "5.3"]
15+
s.swift_version = ["5.1", "5.2", "5.3", "5.4", "5.5"]
1616
s.source = { :git => "https://github.com/dehesa/CodableCSV.git", :tag => "#{s.version}" }
1717
s.source_files = "sources", "sources/**/*.swift"
1818

benchmarks/PerformanceTests.swift

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import CodableCSV
33

44
/// Tests checking the regular encoding usage.
55
final class PerformanceTests: XCTestCase {
6-
override func setUp() {
7-
self.continueAfterFailure = false
8-
}
6+
override func setUp() {
7+
self.continueAfterFailure = false
8+
}
99
}
1010

1111
extension PerformanceTests {
12-
/// Tests the encoding of an empty.
13-
func testEmptyFile() throws {
14-
// XCTSkipUnless(<#T##expression: Bool##Bool#>, <#T##message: String?##String?#>)
15-
#if !DEBUG
16-
print("Hello RELEASE")
17-
#endif
18-
}
12+
/// Tests the encoding of an empty.
13+
func testEmptyFile() throws {
14+
// XCTSkipUnless(<#T##expression: Bool##Bool#>, <#T##message: String?##String?#>)
15+
#if !DEBUG
16+
print("Hello RELEASE")
17+
#endif
18+
}
1919
}

sources/Delimiter.swift

+117-117
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,133 @@
11
/// Separators scalars/strings.
22
public enum Delimiter {
3-
/// The CSV pair of delimiters (field & row delimiters).
4-
public typealias Pair = (field: Self.Field, row: Self.Row)
3+
/// The CSV pair of delimiters (field & row delimiters).
4+
public typealias Pair = (field: Self.Field, row: Self.Row)
55
}
66

77
extension Delimiter {
8-
/// The delimiter between fields/values.
8+
/// The delimiter between fields/values.
9+
///
10+
/// If the delimiter is initialized with `nil`, it implies the field delimiter is unknown and the system should try to figure it out.
11+
public struct Field: ExpressibleByNilLiteral, ExpressibleByStringLiteral, CustomStringConvertible {
12+
/// The accepted field delimiter. Usually a comma `,`.
913
///
10-
/// If the delimiter is initialized with `nil`, it implies the field delimiter is unknown and the system should try to figure it out.
11-
public struct Field: ExpressibleByNilLiteral, ExpressibleByStringLiteral, CustomStringConvertible {
12-
/// The accepted field delimiter. Usually a comma `,`.
13-
///
14-
/// If it's empty, the field delimiter is unknown.
15-
internal let scalars: [Unicode.Scalar]
16-
17-
public init(nilLiteral: ()) {
18-
self.scalars = Array()
19-
}
20-
21-
public init(unicodeScalarLiteral value: Unicode.Scalar) {
22-
self.scalars = [value]
23-
}
24-
25-
public init(stringLiteral value: String) {
26-
precondition(!value.isEmpty)
27-
self.scalars = Array(value.unicodeScalars)
28-
}
29-
30-
/// The field delimiter is represented by the given `String`-like type.
31-
/// - parameter delimiter: The exact composition of the field delimiter. If empty, the initializer fails returning `nil`.
32-
public init?<S:StringProtocol>(_ delimiter: S) {
33-
guard !delimiter.isEmpty else { return nil }
34-
self.scalars = Array(delimiter.unicodeScalars)
35-
}
36-
37-
/// Boolean indicating if the exact unicode scalar composition for the field delimiter is known or unknown.
38-
internal var isKnown: Bool {
39-
!self.scalars.isEmpty
40-
}
41-
42-
/// Returns the `String` representation of the field delimiter.
43-
public var description: String {
44-
String(String.UnicodeScalarView(self.scalars))
45-
}
14+
/// If it's empty, the field delimiter is unknown.
15+
let scalars: [Unicode.Scalar]
16+
17+
public init(nilLiteral: ()) {
18+
self.scalars = Array()
19+
}
20+
21+
public init(unicodeScalarLiteral value: Unicode.Scalar) {
22+
self.scalars = [value]
23+
}
24+
25+
public init(stringLiteral value: String) {
26+
precondition(!value.isEmpty)
27+
self.scalars = Array(value.unicodeScalars)
28+
}
29+
30+
/// The field delimiter is represented by the given `String`-like type.
31+
/// - parameter delimiter: The exact composition of the field delimiter. If empty, the initializer fails returning `nil`.
32+
public init?<S:StringProtocol>(_ delimiter: S) {
33+
guard !delimiter.isEmpty else { return nil }
34+
self.scalars = Array(delimiter.unicodeScalars)
4635
}
36+
37+
/// Boolean indicating if the exact unicode scalar composition for the field delimiter is known or unknown.
38+
var isKnown: Bool {
39+
!self.scalars.isEmpty
40+
}
41+
42+
/// Returns the `String` representation of the field delimiter.
43+
public var description: String {
44+
String(String.UnicodeScalarView(self.scalars))
45+
}
46+
}
4747
}
4848

4949
extension Delimiter {
50-
/// The delimiter between rows.
50+
/// The delimiter between rows.
51+
///
52+
/// If the delimiter is initialized with `nil`, it implies the row delimiter is unknown and the system should try to figure it out.
53+
public struct Row: ExpressibleByStringLiteral, ExpressibleByNilLiteral, CustomStringConvertible {
54+
/// All the accepted row delimiters. Usually, it is only one.
55+
/// - invariant: The elements of the set (i.e. the arrays) always contain at least one element.
56+
let scalars: Set<[Unicode.Scalar]>
57+
58+
public init(nilLiteral: ()) {
59+
self.scalars = Set()
60+
}
61+
62+
public init(unicodeScalarLiteral value: Unicode.Scalar) {
63+
var delimiters = Set<[Unicode.Scalar]>(minimumCapacity: 1)
64+
delimiters.insert([value])
65+
self.scalars = delimiters
66+
}
67+
68+
public init(stringLiteral value: String) {
69+
precondition(!value.isEmpty)
70+
71+
var delimiters = Set<[Unicode.Scalar]>(minimumCapacity: 1)
72+
delimiters.insert(Array(value.unicodeScalars))
73+
self.scalars = delimiters
74+
}
75+
76+
/// Creates one or more possible row delimiters.
77+
/// - parameter delimiters:The exact composition of the row delimiters. If any of the `delimiters` is empty, the initializer fails returning `nil`.
78+
public init?<S:StringProtocol>(_ delimiters: S...) {
79+
let scalars: [[Unicode.Scalar]] = delimiters.compactMap {
80+
guard !$0.isEmpty else { return nil }
81+
return Array($0.unicodeScalars)
82+
}
83+
guard !scalars.isEmpty else { return nil }
84+
self.scalars = Set(scalars)
85+
}
86+
87+
/// Specifies two row delimiters: CR (Carriage Return) LF (Line Feed) `\r\n` and s single line feed `\n`.
5188
///
52-
/// If the delimiter is initialized with `nil`, it implies the row delimiter is unknown and the system should try to figure it out.
53-
public struct Row: ExpressibleByStringLiteral, ExpressibleByNilLiteral, CustomStringConvertible {
54-
/// All the accepted row delimiters. Usually, it is only one.
55-
/// - invariant: The elements of the set (i.e. the arrays) always contain at least one element.
56-
internal let scalars: Set<[Unicode.Scalar]>
57-
58-
/// Specifies two row delimiters: CR (Carriage Return) LF (Line Feed) `\r\n` and s single line feed `\n`.
59-
///
60-
/// This delimiter is intended to be used with CSVs where the end of the row may be marked with a CRLF sometimes and other times with LF.
61-
public static var standard: Self {
62-
self.init("\n", "\r\n")!
63-
}
64-
65-
public init(nilLiteral: ()) {
66-
self.scalars = Set()
67-
}
68-
69-
public init(unicodeScalarLiteral value: Unicode.Scalar) {
70-
var delimiters = Set<[Unicode.Scalar]>(minimumCapacity: 1)
71-
delimiters.insert([value])
72-
self.scalars = delimiters
73-
}
74-
75-
public init(stringLiteral value: String) {
76-
precondition(!value.isEmpty)
77-
78-
var delimiters = Set<[Unicode.Scalar]>(minimumCapacity: 1)
79-
delimiters.insert(Array(value.unicodeScalars))
80-
self.scalars = delimiters
81-
}
82-
83-
/// Creates one or more possible row delimiters.
84-
/// - parameter delimiters:The exact composition of the row delimiters. If any of the `delimiters` is empty, the initializer fails returning `nil`.
85-
public init?<S:StringProtocol>(_ delimiters: S...) {
86-
let scalars: [[Unicode.Scalar]] = delimiters.compactMap {
87-
guard !$0.isEmpty else { return nil }
88-
return Array($0.unicodeScalars)
89-
}
90-
guard !scalars.isEmpty else { return nil }
91-
self.scalars = Set(scalars)
92-
}
93-
94-
/// Boolean indicating if the exact unicode scalar composition for the row delimiter is known or unknown.
95-
internal var isKnown: Bool {
96-
!self.scalars.isEmpty
97-
}
98-
99-
/// Returns the `String` representation of the row delimiter.
100-
///
101-
/// If more than one row has been provided, the `String` with less number of characters and less value (i.e. less Integer value) is selected.
102-
public var description: String {
103-
String(String.UnicodeScalarView(self.scalars.min {
104-
guard $0.count == $1.count else { return $0.count < $1.count }
105-
for (lhs, rhs) in zip($0, $1) where lhs != rhs { return lhs < rhs }
106-
return true
107-
}!))
108-
}
89+
/// This delimiter is intended to be used with CSVs where the end of the row may be marked with a CRLF sometimes and other times with LF.
90+
public static var standard: Self {
91+
self.init("\n", "\r\n")!
10992
}
93+
94+
/// Boolean indicating if the exact unicode scalar composition for the row delimiter is known or unknown.
95+
var isKnown: Bool {
96+
!self.scalars.isEmpty
97+
}
98+
99+
/// Returns the `String` representation of the row delimiter.
100+
///
101+
/// If more than one row has been provided, the `String` with less number of characters and less value (i.e. less Integer value) is selected.
102+
public var description: String {
103+
String(String.UnicodeScalarView(self.scalars.min {
104+
guard $0.count == $1.count else { return $0.count < $1.count }
105+
for (lhs, rhs) in zip($0, $1) where lhs != rhs { return lhs < rhs }
106+
return true
107+
}!))
108+
}
109+
}
110110
}
111111

112-
internal extension Delimiter {
113-
/// Contains the exact composition of a CSV field and row delimiter.
114-
struct Scalars {
115-
/// The exact composition of unicode scalars indetifying a field delimiter.
116-
/// - invariant: The array always contains at least one element.
117-
let field: [Unicode.Scalar]
118-
/// All possile row delimiters specifying its exact compositon of unicode scalars.
119-
/// - invariant: The set always contains at least one element and all set elements always contain at least on scalar.
120-
let row: Set<[Unicode.Scalar]>
121-
122-
/// Designated initializer checking that the delimiters aren't empty and the field delimiter is not included in the row delimiter.
123-
/// - parameter field: The exact composition of the field delimiter. If empty, `nil` is returned.
124-
/// - parameter row: The exact composition of all possible row delimiters. If it is empty or any of its elements is an empty array, `nil` is returned.
125-
init?(field: [Unicode.Scalar], row: Set<[Unicode.Scalar]>) {
126-
guard !field.isEmpty else { return nil }
127-
self.field = field
128-
guard !row.isEmpty, row.allSatisfy({ !$0.isEmpty }) else { return nil }
129-
self.row = row
130-
guard self.row.allSatisfy({ $0 != self.field }) else { return nil }
131-
}
112+
extension Delimiter {
113+
/// Contains the exact composition of a CSV field and row delimiter.
114+
struct Scalars {
115+
/// The exact composition of unicode scalars indetifying a field delimiter.
116+
/// - invariant: The array always contains at least one element.
117+
let field: [Unicode.Scalar]
118+
/// All possile row delimiters specifying its exact compositon of unicode scalars.
119+
/// - invariant: The set always contains at least one element and all set elements always contain at least on scalar.
120+
let row: Set<[Unicode.Scalar]>
121+
122+
/// Designated initializer checking that the delimiters aren't empty and the field delimiter is not included in the row delimiter.
123+
/// - parameter field: The exact composition of the field delimiter. If empty, `nil` is returned.
124+
/// - parameter row: The exact composition of all possible row delimiters. If it is empty or any of its elements is an empty array, `nil` is returned.
125+
init?(field: [Unicode.Scalar], row: Set<[Unicode.Scalar]>) {
126+
guard !field.isEmpty else { return nil }
127+
self.field = field
128+
guard !row.isEmpty, row.allSatisfy({ !$0.isEmpty }) else { return nil }
129+
self.row = row
130+
guard self.row.allSatisfy({ $0 != self.field }) else { return nil }
132131
}
132+
}
133133
}

0 commit comments

Comments
 (0)