Skip to content

Commit 193aa03

Browse files
committed
Update code style
1 parent 4ddebf9 commit 193aa03

File tree

10 files changed

+597
-643
lines changed

10 files changed

+597
-643
lines changed

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Frameworks/CSVImporter/CSVImporter.swift

+362-370
Large diffs are not rendered by default.
+39-47
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,44 @@
1-
//
2-
// FileSource.swift
3-
// CSVImporter
4-
//
5-
// Created by Cihat Gündüz on 10.12.17.
6-
// Copyright © 2017 Flinesoft. All rights reserved.
7-
//
8-
91
import Foundation
102

113
class FileSource: Source {
12-
private let textFile: TextFile
13-
private let encoding: String.Encoding
14-
private var lineEnding: LineEnding
15-
16-
init(textFile: TextFile, encoding: String.Encoding, lineEnding: LineEnding) {
17-
self.textFile = textFile
18-
self.encoding = encoding
19-
self.lineEnding = lineEnding
20-
}
21-
22-
func forEach(_ closure: (String) -> Void) {
23-
if lineEnding == .unknown {
24-
lineEnding = lineEndingForFile()
25-
}
26-
27-
guard let csvStreamReader = textFile.streamReader(lineEnding: lineEnding, chunkSize: chunkSize) else { return }
28-
csvStreamReader.forEach(closure)
29-
}
30-
31-
/// Determines the line ending for the CSV file
32-
///
33-
/// - Returns: the lineEnding for the CSV file or default of NL.
34-
private func lineEndingForFile() -> LineEnding {
35-
var lineEnding: LineEnding = .newLine
36-
if let fileHandle = textFile.handleForReading {
37-
if let data = (fileHandle.readData(ofLength: chunkSize) as NSData).mutableCopy() as? NSMutableData {
38-
if let contents = NSString(bytesNoCopy: data.mutableBytes, length: data.length, encoding: encoding.rawValue, freeWhenDone: false) {
39-
if contents.contains(LineEnding.carriageReturnLineFeed.rawValue) {
40-
lineEnding = .carriageReturnLineFeed
41-
} else if contents.contains(LineEnding.newLine.rawValue) {
42-
lineEnding = .newLine
43-
} else if contents.contains(LineEnding.carriageReturn.rawValue) {
44-
lineEnding = .carriageReturn
45-
}
46-
}
4+
private let textFile: TextFile
5+
private let encoding: String.Encoding
6+
private var lineEnding: LineEnding
7+
8+
init(textFile: TextFile, encoding: String.Encoding, lineEnding: LineEnding) {
9+
self.textFile = textFile
10+
self.encoding = encoding
11+
self.lineEnding = lineEnding
12+
}
13+
14+
func forEach(_ closure: (String) -> Void) {
15+
if lineEnding == .unknown {
16+
lineEnding = lineEndingForFile()
17+
}
18+
19+
guard let csvStreamReader = textFile.streamReader(lineEnding: lineEnding, chunkSize: chunkSize) else { return }
20+
csvStreamReader.forEach(closure)
21+
}
22+
23+
/// Determines the line ending for the CSV file
24+
///
25+
/// - Returns: the lineEnding for the CSV file or default of NL.
26+
private func lineEndingForFile() -> LineEnding {
27+
var lineEnding: LineEnding = .newLine
28+
if let fileHandle = textFile.handleForReading {
29+
if let data = (fileHandle.readData(ofLength: chunkSize) as NSData).mutableCopy() as? NSMutableData {
30+
if let contents = NSString(bytesNoCopy: data.mutableBytes, length: data.length, encoding: encoding.rawValue, freeWhenDone: false) {
31+
if contents.contains(LineEnding.carriageReturnLineFeed.rawValue) {
32+
lineEnding = .carriageReturnLineFeed
33+
} else if contents.contains(LineEnding.newLine.rawValue) {
34+
lineEnding = .newLine
35+
} else if contents.contains(LineEnding.carriageReturn.rawValue) {
36+
lineEnding = .carriageReturn
37+
}
4738
}
48-
}
49-
50-
return lineEnding
51-
}
39+
}
40+
}
41+
42+
return lineEnding
43+
}
5244
}

Frameworks/CSVImporter/Globals.swift

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
//
2-
// Created by Cihat Gündüz on 28.09.18.
3-
// Copyright © 2018 Flinesoft. All rights reserved.
4-
//
5-
61
import Foundation
72

83
#if os(Linux)
9-
func autoreleasepool(_ closure: () -> Void) {
10-
closure()
11-
}
4+
func autoreleasepool(_ closure: () -> Void) {
5+
closure()
6+
}
127
#endif

Frameworks/CSVImporter/Source.swift

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
//
2-
// Source.swift
3-
// CSVImporter
4-
//
5-
// Created by Cihat Gündüz on 10.12.17.
6-
// Copyright © 2017 Flinesoft. All rights reserved.
7-
//
8-
91
import Foundation
102

113
let chunkSize = 4_096
124

135
protocol Source {
14-
func forEach(_ closure: (String) -> Void)
6+
func forEach(_ closure: (String) -> Void)
157
}
+22-30
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,27 @@
1-
//
2-
// StringSource.swift
3-
// CSVImporter
4-
//
5-
// Created by Cihat Gündüz on 10.12.17.
6-
// Copyright © 2017 Flinesoft. All rights reserved.
7-
//
8-
91
import Foundation
102

113
class StringSource: Source {
12-
private let lines: [String]
13-
14-
init(contentString: String, lineEnding: LineEnding) {
15-
let correctedLineEnding: LineEnding = {
16-
if lineEnding == .unknown {
17-
if contentString.contains(LineEnding.carriageReturnLineFeed.rawValue) {
18-
return .carriageReturnLineFeed
19-
} else if contentString.contains(LineEnding.newLine.rawValue) {
20-
return .newLine
21-
} else if contentString.contains(LineEnding.carriageReturn.rawValue) {
22-
return .carriageReturn
23-
}
4+
private let lines: [String]
5+
6+
init(contentString: String, lineEnding: LineEnding) {
7+
let correctedLineEnding: LineEnding = {
8+
if lineEnding == .unknown {
9+
if contentString.contains(LineEnding.carriageReturnLineFeed.rawValue) {
10+
return .carriageReturnLineFeed
11+
} else if contentString.contains(LineEnding.newLine.rawValue) {
12+
return .newLine
13+
} else if contentString.contains(LineEnding.carriageReturn.rawValue) {
14+
return .carriageReturn
2415
}
25-
26-
return lineEnding
27-
}()
28-
29-
lines = contentString.components(separatedBy: correctedLineEnding.rawValue)
30-
}
31-
32-
func forEach(_ closure: (String) -> Void) {
33-
lines.forEach(closure)
34-
}
16+
}
17+
18+
return lineEnding
19+
}()
20+
21+
lines = contentString.components(separatedBy: correctedLineEnding.rawValue)
22+
}
23+
24+
func forEach(_ closure: (String) -> Void) {
25+
lines.forEach(closure)
26+
}
3527
}

Frameworks/CSVImporter/TextFile.swift

+28-34
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,44 @@
1-
//
2-
// Created by Cihat Gündüz on 16.12.16.
3-
// Copyright © 2016 Flinesoft. All rights reserved.
4-
//
51
// Originally copied from https://github.com/nvzqz/FileKit/blob/feature-swift3/Sources/TextFile.swift
6-
//
7-
82
import Foundation
93

104
/// A representation of a filesystem text file.
115
///
126
/// The data type is String.
137
class TextFile {
14-
/// The text file's string encoding.
15-
fileprivate var encoding: String.Encoding
16-
17-
/// The file's filesystem path.
18-
fileprivate var path: String
19-
20-
/// Initializes a text file from a path with an encoding.
21-
///
22-
/// - Parameter path: The path to be created a text file from.
23-
/// - Parameter encoding: The encoding to be used for the text file.
24-
init(path: String, encoding: String.Encoding) {
25-
self.path = path
26-
self.encoding = encoding
27-
}
8+
/// The text file's string encoding.
9+
fileprivate var encoding: String.Encoding
10+
11+
/// The file's filesystem path.
12+
fileprivate var path: String
13+
14+
/// Initializes a text file from a path with an encoding.
15+
///
16+
/// - Parameter path: The path to be created a text file from.
17+
/// - Parameter encoding: The encoding to be used for the text file.
18+
init(path: String, encoding: String.Encoding) {
19+
self.path = path
20+
self.encoding = encoding
21+
}
2822
}
2923

3024
// MARK: Line Reader
3125
extension TextFile {
32-
/// Provide a reader to read line by line.
33-
///
34-
/// - Parameter delimiter: the line delimiter (default: \n)
35-
/// - Parameter chunkSize: size of buffer (default: 4096)
36-
///
37-
/// - Returns: the `TextFileStreamReader`
38-
func streamReader(lineEnding: LineEnding, chunkSize: Int) -> TextFileStreamReader? {
39-
return TextFileStreamReader(path: self.path, lineEnding: lineEnding, encoding: encoding, chunkSize: chunkSize)
40-
}
26+
/// Provide a reader to read line by line.
27+
///
28+
/// - Parameter delimiter: the line delimiter (default: \n)
29+
/// - Parameter chunkSize: size of buffer (default: 4096)
30+
///
31+
/// - Returns: the `TextFileStreamReader`
32+
func streamReader(lineEnding: LineEnding, chunkSize: Int) -> TextFileStreamReader? {
33+
return TextFileStreamReader(path: self.path, lineEnding: lineEnding, encoding: encoding, chunkSize: chunkSize)
34+
}
4135
}
4236

4337
// MARK: File Handle
4438
extension TextFile {
45-
/// Returns a file handle for reading from `self`, or `nil` if `self`
46-
/// doesn't exist.
47-
var handleForReading: FileHandle? {
48-
return FileHandle(forReadingAtPath: path)
49-
}
39+
/// Returns a file handle for reading from `self`, or `nil` if `self`
40+
/// doesn't exist.
41+
var handleForReading: FileHandle? {
42+
return FileHandle(forReadingAtPath: path)
43+
}
5044
}

0 commit comments

Comments
 (0)