-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathReaderConfiguration.swift
More file actions
51 lines (46 loc) · 1.91 KB
/
ReaderConfiguration.swift
File metadata and controls
51 lines (46 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import Foundation
extension CSVReader {
/// Configuration for how to read CSV data.
public struct Configuration {
/// The encoding used to identify the underlying data or `nil` if you want the CSV reader to try to figure it out.
///
/// If no encoding is provided and the input data doesn't contain a Byte Order Marker (BOM), UTF8 is presumed.
public var encoding: String.Encoding?
/// The field and row delimiters.
public var delimiters: Delimiter.Pair
/// The strategy to allow/disable escaped fields and how.
public var escapingStrategy: Strategy.Escaping
/// Indication on whether the CSV will contain a header row or not, or that information is unknown and it should try to be inferred.
public var headerStrategy: Strategy.Header
/// Trims the given characters at the beginning and end of each row, and between fields.
public var trimStrategy: CharacterSet
/// Boolean indicating whether the data/file/string should be completely parsed at reader's initialization.
public var presample: Bool
/// Designated initializer setting the default values.
public init() {
self.encoding = nil
self.delimiters = (field: ",", row: .standard)
self.escapingStrategy = .doubleQuote
self.headerStrategy = .none
self.trimStrategy = CharacterSet()
self.presample = false
}
}
}
extension Strategy {
/// Indication on whether the CSV file contains headers or not.
public enum Header: ExpressibleByNilLiteral, ExpressibleByBooleanLiteral {
/// The CSV contains no header row.
case none
/// The CSV contains a single header row.
case firstLine
// /// It is not known whether the CSV contains a header row. The library will try to infer it!
// case unknown
public init(nilLiteral: ()) {
self = .none
}
public init(booleanLiteral value: BooleanLiteralType) {
self = (value) ? .firstLine : .none
}
}
}