Code cleanup
This commit is contained in:
parent
be8d1fda41
commit
28c54df853
|
@ -21,6 +21,10 @@
|
|||
0E47EEBA1DBB268000EBF783 /* CSVConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E47EEB81DBB268000EBF783 /* CSVConfiguration.swift */; };
|
||||
0E47EEBB1DBB268000EBF783 /* CSVConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E47EEB81DBB268000EBF783 /* CSVConfiguration.swift */; };
|
||||
0E47EEBC1DBB268000EBF783 /* CSVConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E47EEB81DBB268000EBF783 /* CSVConfiguration.swift */; };
|
||||
0E47EEC11DBCDB1800EBF783 /* CSV+iterator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E47EEC01DBCDB1800EBF783 /* CSV+iterator.swift */; };
|
||||
0E47EEC21DBCDB1800EBF783 /* CSV+iterator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E47EEC01DBCDB1800EBF783 /* CSV+iterator.swift */; };
|
||||
0E47EEC31DBCDB1800EBF783 /* CSV+iterator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E47EEC01DBCDB1800EBF783 /* CSV+iterator.swift */; };
|
||||
0E47EEC41DBCDB1800EBF783 /* CSV+iterator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E47EEC01DBCDB1800EBF783 /* CSV+iterator.swift */; };
|
||||
0E7E8C8C1D0BC7BB0057A1C1 /* CSV.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E7E8C811D0BC7BB0057A1C1 /* CSV.framework */; };
|
||||
0E7E8CA11D0BC7F10057A1C1 /* CSV.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E7E8C9D1D0BC7F10057A1C1 /* CSV.swift */; };
|
||||
0E7E8CA21D0BC7F10057A1C1 /* CSVError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E7E8C9E1D0BC7F10057A1C1 /* CSVError.swift */; };
|
||||
|
@ -46,10 +50,6 @@
|
|||
0E9317D51D0DB2F200AC20A0 /* CSV+init.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E9317D31D0DB2F200AC20A0 /* CSV+init.swift */; };
|
||||
0E9317D61D0DB2F200AC20A0 /* CSV+init.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E9317D31D0DB2F200AC20A0 /* CSV+init.swift */; };
|
||||
0E9317D71D0DB2F200AC20A0 /* CSV+init.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E9317D31D0DB2F200AC20A0 /* CSV+init.swift */; };
|
||||
0E9317D91D0DB30800AC20A0 /* CSV+subscript.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E9317D81D0DB30800AC20A0 /* CSV+subscript.swift */; };
|
||||
0E9317DA1D0DB30800AC20A0 /* CSV+subscript.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E9317D81D0DB30800AC20A0 /* CSV+subscript.swift */; };
|
||||
0E9317DB1D0DB30800AC20A0 /* CSV+subscript.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E9317D81D0DB30800AC20A0 /* CSV+subscript.swift */; };
|
||||
0E9317DC1D0DB30800AC20A0 /* CSV+subscript.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E9317D81D0DB30800AC20A0 /* CSV+subscript.swift */; };
|
||||
0E9317DE1D0DBCC500AC20A0 /* ReadmeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E9317DD1D0DBCC500AC20A0 /* ReadmeTests.swift */; };
|
||||
0E9317DF1D0DBCC500AC20A0 /* ReadmeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E9317DD1D0DBCC500AC20A0 /* ReadmeTests.swift */; };
|
||||
0E9317E01D0DBCC500AC20A0 /* ReadmeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E9317DD1D0DBCC500AC20A0 /* ReadmeTests.swift */; };
|
||||
|
@ -92,6 +92,7 @@
|
|||
0E3CE36B1DB5281E00FA45CF /* UnicodeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnicodeTests.swift; sourceTree = "<group>"; };
|
||||
0E3CE36F1DB529D700FA45CF /* TrimFieldsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrimFieldsTests.swift; sourceTree = "<group>"; };
|
||||
0E47EEB81DBB268000EBF783 /* CSVConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSVConfiguration.swift; sourceTree = SOURCE_ROOT; };
|
||||
0E47EEC01DBCDB1800EBF783 /* CSV+iterator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CSV+iterator.swift"; sourceTree = "<group>"; };
|
||||
0E7E8C811D0BC7BB0057A1C1 /* CSV.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CSV.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
0E7E8C8B1D0BC7BB0057A1C1 /* CSVTests-iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "CSVTests-iOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
0E7E8C9D1D0BC7F10057A1C1 /* CSV.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CSV.swift; sourceTree = "<group>"; };
|
||||
|
@ -107,7 +108,6 @@
|
|||
0E7E8CE81D0BCD0B0057A1C1 /* CSV.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CSV.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
0E7E8CF11D0BCD0B0057A1C1 /* CSVTests-tvOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "CSVTests-tvOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
0E9317D31D0DB2F200AC20A0 /* CSV+init.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CSV+init.swift"; sourceTree = "<group>"; };
|
||||
0E9317D81D0DB30800AC20A0 /* CSV+subscript.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CSV+subscript.swift"; sourceTree = "<group>"; };
|
||||
0E9317DD1D0DBCC500AC20A0 /* ReadmeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReadmeTests.swift; sourceTree = "<group>"; };
|
||||
0EA2AB7B1D183B45003EC967 /* BinaryReader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BinaryReader.swift; sourceTree = "<group>"; };
|
||||
0EA2AB801D183BA9003EC967 /* UnicodeIterator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnicodeIterator.swift; sourceTree = "<group>"; };
|
||||
|
@ -199,7 +199,7 @@
|
|||
0EA2AB7B1D183B45003EC967 /* BinaryReader.swift */,
|
||||
0E7E8C9D1D0BC7F10057A1C1 /* CSV.swift */,
|
||||
0E9317D31D0DB2F200AC20A0 /* CSV+init.swift */,
|
||||
0E9317D81D0DB30800AC20A0 /* CSV+subscript.swift */,
|
||||
0E47EEC01DBCDB1800EBF783 /* CSV+iterator.swift */,
|
||||
0E47EEB81DBB268000EBF783 /* CSVConfiguration.swift */,
|
||||
0E7E8C9E1D0BC7F10057A1C1 /* CSVError.swift */,
|
||||
0E7E8C9F1D0BC7F10057A1C1 /* CSVVersion.h */,
|
||||
|
@ -535,7 +535,7 @@
|
|||
files = (
|
||||
0E9317D51D0DB2F200AC20A0 /* CSV+init.swift in Sources */,
|
||||
0EA2AB821D183BA9003EC967 /* UnicodeIterator.swift in Sources */,
|
||||
0E9317DA1D0DB30800AC20A0 /* CSV+subscript.swift in Sources */,
|
||||
0E47EEC21DBCDB1800EBF783 /* CSV+iterator.swift in Sources */,
|
||||
0E7E8CA11D0BC7F10057A1C1 /* CSV.swift in Sources */,
|
||||
0E0F160F1D197DB800C92580 /* Endian.swift in Sources */,
|
||||
0E47EEBA1DBB268000EBF783 /* CSVConfiguration.swift in Sources */,
|
||||
|
@ -562,7 +562,7 @@
|
|||
files = (
|
||||
0E9317D71D0DB2F200AC20A0 /* CSV+init.swift in Sources */,
|
||||
0EA2AB841D183BA9003EC967 /* UnicodeIterator.swift in Sources */,
|
||||
0E9317DC1D0DB30800AC20A0 /* CSV+subscript.swift in Sources */,
|
||||
0E47EEC41DBCDB1800EBF783 /* CSV+iterator.swift in Sources */,
|
||||
0E7E8CBE1D0BC9D70057A1C1 /* CSV.swift in Sources */,
|
||||
0E0F16111D197DB800C92580 /* Endian.swift in Sources */,
|
||||
0E47EEBC1DBB268000EBF783 /* CSVConfiguration.swift in Sources */,
|
||||
|
@ -577,7 +577,7 @@
|
|||
files = (
|
||||
0E9317D41D0DB2F200AC20A0 /* CSV+init.swift in Sources */,
|
||||
0EA2AB811D183BA9003EC967 /* UnicodeIterator.swift in Sources */,
|
||||
0E9317D91D0DB30800AC20A0 /* CSV+subscript.swift in Sources */,
|
||||
0E47EEC11DBCDB1800EBF783 /* CSV+iterator.swift in Sources */,
|
||||
0E7E8CE01D0BCA8E0057A1C1 /* CSV.swift in Sources */,
|
||||
0E0F160E1D197DB800C92580 /* Endian.swift in Sources */,
|
||||
0E47EEB91DBB268000EBF783 /* CSVConfiguration.swift in Sources */,
|
||||
|
@ -604,7 +604,7 @@
|
|||
files = (
|
||||
0E9317D61D0DB2F200AC20A0 /* CSV+init.swift in Sources */,
|
||||
0EA2AB831D183BA9003EC967 /* UnicodeIterator.swift in Sources */,
|
||||
0E9317DB1D0DB30800AC20A0 /* CSV+subscript.swift in Sources */,
|
||||
0E47EEC31DBCDB1800EBF783 /* CSV+iterator.swift in Sources */,
|
||||
0E7E8D001D0BCDCF0057A1C1 /* CSV.swift in Sources */,
|
||||
0E0F16101D197DB800C92580 /* Endian.swift in Sources */,
|
||||
0E47EEBB1DBB268000EBF783 /* CSVConfiguration.swift in Sources */,
|
||||
|
|
|
@ -22,24 +22,6 @@ extension CSV {
|
|||
try self.init(stream: stream, codecType: UTF8.self, config: config)
|
||||
}
|
||||
|
||||
// MARK: - deprecated
|
||||
|
||||
/// Unavailable.
|
||||
@available(*, unavailable, message: "Use init(stream:config:) instead")
|
||||
public init(
|
||||
stream: InputStream,
|
||||
hasHeaderRow: Bool = defaultHasHeaderRow,
|
||||
trimFields: Bool = defaultTrimFields,
|
||||
delimiter: UnicodeScalar = defaultDelimiter) throws {
|
||||
|
||||
let config = CSVConfiguration(
|
||||
hasHeaderRow: hasHeaderRow,
|
||||
trimFields: trimFields,
|
||||
delimiter: delimiter
|
||||
)
|
||||
try self.init(stream: stream, codecType: UTF8.self, config: config)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension CSV {
|
||||
|
@ -56,23 +38,4 @@ extension CSV {
|
|||
try self.init(iterator: iterator, config: config)
|
||||
}
|
||||
|
||||
// MARK: - deprecated
|
||||
|
||||
/// Unavailable.
|
||||
@available(*, unavailable, message: "Use init(string:config:) instead")
|
||||
public init(
|
||||
string: String,
|
||||
hasHeaderRow: Bool = defaultHasHeaderRow,
|
||||
trimFields: Bool = defaultTrimFields,
|
||||
delimiter: UnicodeScalar = defaultDelimiter) throws {
|
||||
|
||||
let iterator = string.unicodeScalars.makeIterator()
|
||||
let config = CSVConfiguration(
|
||||
hasHeaderRow: hasHeaderRow,
|
||||
trimFields: trimFields,
|
||||
delimiter: delimiter
|
||||
)
|
||||
try self.init(iterator: iterator, config: config)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
//
|
||||
// CSV+iterator.swift
|
||||
// CSV
|
||||
//
|
||||
// Created by Yasuhiro Hatta on 2016/10/23.
|
||||
// Copyright © 2016年 yaslab. All rights reserved.
|
||||
//
|
||||
|
||||
extension CSV: IteratorProtocol, Sequence {
|
||||
|
||||
/// No overview available.
|
||||
public mutating func next() -> Row? {
|
||||
guard let row = readRow() else {
|
||||
return nil
|
||||
}
|
||||
return Row(data: row, headerRow: headerRow)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension CSV {
|
||||
|
||||
/// No overview available.
|
||||
public struct Row: RandomAccessCollection {
|
||||
|
||||
private let data: [String]
|
||||
private let headerRow: [String]?
|
||||
|
||||
internal init(data: [String], headerRow: [String]?) {
|
||||
self.data = data
|
||||
self.headerRow = headerRow
|
||||
}
|
||||
|
||||
// MARK: - RandomAccessCollection
|
||||
|
||||
/// No overview available.
|
||||
public var startIndex: Int {
|
||||
return data.startIndex
|
||||
}
|
||||
|
||||
/// No overview available.
|
||||
public var endIndex: Int {
|
||||
return data.endIndex
|
||||
}
|
||||
|
||||
/// No overview available.
|
||||
public func index(before i: Int) -> Int {
|
||||
return data.index(before: i)
|
||||
}
|
||||
|
||||
/// No overview available.
|
||||
public func index(after i: Int) -> Int {
|
||||
return data.index(after: i)
|
||||
}
|
||||
|
||||
/// No overview available.
|
||||
public subscript(index: Int) -> String {
|
||||
return data[index]
|
||||
}
|
||||
|
||||
// MARK: - Public method
|
||||
|
||||
/// No overview available.
|
||||
public subscript(key: String) -> String? {
|
||||
assert(headerRow != nil, "CSVConfiguration.hasHeaderRow must be true")
|
||||
guard let index = headerRow!.index(of: key) else {
|
||||
return nil
|
||||
}
|
||||
return data[index]
|
||||
}
|
||||
|
||||
/// No overview available.
|
||||
public func toArray() -> [String] {
|
||||
return data
|
||||
}
|
||||
|
||||
/// No overview available.
|
||||
public func toDictionary() -> [String : String] {
|
||||
assert(headerRow != nil, "CSVConfiguration.hasHeaderRow must be true")
|
||||
var dictionary: [String : String] = [:]
|
||||
for (key, value) in zip(headerRow!, data) {
|
||||
dictionary[key] = value
|
||||
}
|
||||
return dictionary
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
//
|
||||
// CSV+subscript.swift
|
||||
// CSV
|
||||
//
|
||||
// Created by Yasuhiro Hatta on 2016/06/13.
|
||||
// Copyright © 2016 yaslab. All rights reserved.
|
||||
//
|
||||
|
||||
extension CSV {
|
||||
|
||||
/// Unavailable
|
||||
@available(*, unavailable, message: "Use CSV.Row.subscript(String) instead")
|
||||
public subscript(key: String) -> String? {
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
|
@ -12,92 +12,9 @@ private let LF = UnicodeScalar(UInt8(0x0a)) // "\n"
|
|||
private let CR = UnicodeScalar(UInt8(0x0d)) // "\r"
|
||||
private let DQUOTE = UnicodeScalar(UInt8(0x22)) // "\""
|
||||
|
||||
extension CSV: Sequence { }
|
||||
|
||||
extension CSV: IteratorProtocol {
|
||||
|
||||
/// No overview available.
|
||||
public mutating func next() -> Row? {
|
||||
guard let row = readRow() else {
|
||||
return nil
|
||||
}
|
||||
return Row(data: row, headerRow: headerRow)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// No overview available.
|
||||
public struct CSV {
|
||||
|
||||
/// No overview available.
|
||||
public typealias HeaderRow = [String]
|
||||
|
||||
/// No overview available.
|
||||
public struct Row: RandomAccessCollection {
|
||||
|
||||
private let data: [String]
|
||||
private let headerRow: HeaderRow?
|
||||
|
||||
internal init(data: [String], headerRow: HeaderRow?) {
|
||||
self.data = data
|
||||
self.headerRow = headerRow
|
||||
}
|
||||
|
||||
// MARK: - RandomAccessCollection
|
||||
|
||||
/// No overview available.
|
||||
public var startIndex: Int {
|
||||
return data.startIndex
|
||||
}
|
||||
|
||||
/// No overview available.
|
||||
public var endIndex: Int {
|
||||
return data.endIndex
|
||||
}
|
||||
|
||||
/// No overview available.
|
||||
public func index(before i: Int) -> Int {
|
||||
return data.index(before: i)
|
||||
}
|
||||
|
||||
/// No overview available.
|
||||
public func index(after i: Int) -> Int {
|
||||
return data.index(after: i)
|
||||
}
|
||||
|
||||
/// No overview available.
|
||||
public subscript(index: Int) -> String {
|
||||
return data[index]
|
||||
}
|
||||
|
||||
// MARK: - Public method
|
||||
|
||||
/// No overview available.
|
||||
public subscript(key: String) -> String? {
|
||||
assert(headerRow != nil, "CSVConfiguration.hasHeaderRow must be true")
|
||||
guard let index = headerRow!.index(of: key) else {
|
||||
return nil
|
||||
}
|
||||
return data[index]
|
||||
}
|
||||
|
||||
/// No overview available.
|
||||
public func toArray() -> [String] {
|
||||
return data
|
||||
}
|
||||
|
||||
/// No overview available.
|
||||
public func toDictionary() -> [String : String] {
|
||||
assert(headerRow != nil, "CSVConfiguration.hasHeaderRow must be true")
|
||||
var dictionary: [String : String] = [:]
|
||||
for (key, value) in zip(headerRow!, data) {
|
||||
dictionary[key] = value
|
||||
}
|
||||
return dictionary
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private var iterator: AnyIterator<UnicodeScalar>
|
||||
private let config: CSVConfiguration
|
||||
|
||||
|
@ -105,7 +22,7 @@ public struct CSV {
|
|||
|
||||
/// CSV header row. To set a value for this property,
|
||||
/// you set `true` to `hasHeaerRow` in initializer.
|
||||
public private(set) var headerRow: HeaderRow? = nil
|
||||
public private(set) var headerRow: [String]? = nil
|
||||
|
||||
internal init<T: IteratorProtocol>(
|
||||
iterator: T,
|
||||
|
@ -123,77 +40,6 @@ public struct CSV {
|
|||
}
|
||||
}
|
||||
|
||||
/// Unavailable.
|
||||
@available(*, unavailable, message: "Use init(stream:codecType:config:) instead")
|
||||
public init<T: UnicodeCodec>(
|
||||
stream: InputStream,
|
||||
codecType: T.Type,
|
||||
hasHeaderRow: Bool = defaultHasHeaderRow,
|
||||
trimFields: Bool = defaultTrimFields,
|
||||
delimiter: UnicodeScalar = defaultDelimiter
|
||||
) throws where T.CodeUnit == UInt8 {
|
||||
|
||||
let reader = try BinaryReader(stream: stream, endian: .unknown, closeOnDeinit: true)
|
||||
let iterator = UnicodeIterator(
|
||||
input: reader.makeUInt8Iterator(),
|
||||
inputEncodingType: codecType
|
||||
)
|
||||
let config = CSVConfiguration(
|
||||
hasHeaderRow: hasHeaderRow,
|
||||
trimFields: trimFields,
|
||||
delimiter: delimiter
|
||||
)
|
||||
try self.init(iterator: iterator, config: config)
|
||||
}
|
||||
|
||||
/// Unavailable.
|
||||
@available(*, unavailable, message: "Use init(stream:codecType:endian:config:) instead")
|
||||
public init<T: UnicodeCodec>(
|
||||
stream: InputStream,
|
||||
codecType: T.Type,
|
||||
endian: Endian = .big,
|
||||
hasHeaderRow: Bool = defaultHasHeaderRow,
|
||||
trimFields: Bool = defaultTrimFields,
|
||||
delimiter: UnicodeScalar = defaultDelimiter
|
||||
) throws where T.CodeUnit == UInt16 {
|
||||
|
||||
let reader = try BinaryReader(stream: stream, endian: endian, closeOnDeinit: true)
|
||||
let iterator = UnicodeIterator(
|
||||
input: reader.makeUInt16Iterator(),
|
||||
inputEncodingType: codecType
|
||||
)
|
||||
let config = CSVConfiguration(
|
||||
hasHeaderRow: hasHeaderRow,
|
||||
trimFields: trimFields,
|
||||
delimiter: delimiter
|
||||
)
|
||||
try self.init(iterator: iterator, config: config)
|
||||
}
|
||||
|
||||
/// Unavailable.
|
||||
@available(*, unavailable, message: "Use init(stream:codecType:endian:config:) instead")
|
||||
public init<T: UnicodeCodec>(
|
||||
stream: InputStream,
|
||||
codecType: T.Type,
|
||||
endian: Endian = .big,
|
||||
hasHeaderRow: Bool = defaultHasHeaderRow,
|
||||
trimFields: Bool = defaultTrimFields,
|
||||
delimiter: UnicodeScalar = defaultDelimiter
|
||||
) throws where T.CodeUnit == UInt32 {
|
||||
|
||||
let reader = try BinaryReader(stream: stream, endian: endian, closeOnDeinit: true)
|
||||
let iterator = UnicodeIterator(
|
||||
input: reader.makeUInt32Iterator(),
|
||||
inputEncodingType: codecType
|
||||
)
|
||||
let config = CSVConfiguration(
|
||||
hasHeaderRow: hasHeaderRow,
|
||||
trimFields: trimFields,
|
||||
delimiter: delimiter
|
||||
)
|
||||
try self.init(iterator: iterator, config: config)
|
||||
}
|
||||
|
||||
/// Create an instance with `InputStream`.
|
||||
///
|
||||
/// - parameter stream: An `InputStream` object. If the stream is not open,
|
||||
|
@ -260,7 +106,7 @@ public struct CSV {
|
|||
|
||||
// MARK: - Parse CSV
|
||||
|
||||
fileprivate mutating func readRow() -> [String]? {
|
||||
internal mutating func readRow() -> [String]? {
|
||||
var c = moveNext()
|
||||
if c == nil {
|
||||
return nil
|
||||
|
@ -371,3 +217,117 @@ public struct CSV {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
extension CSV {
|
||||
|
||||
/// Unavailable.
|
||||
@available(*, unavailable, message: "Use init(stream:codecType:config:) instead")
|
||||
public init<T: UnicodeCodec>(
|
||||
stream: InputStream,
|
||||
codecType: T.Type,
|
||||
hasHeaderRow: Bool = defaultHasHeaderRow,
|
||||
trimFields: Bool = defaultTrimFields,
|
||||
delimiter: UnicodeScalar = defaultDelimiter
|
||||
) throws where T.CodeUnit == UInt8 {
|
||||
|
||||
let reader = try BinaryReader(stream: stream, endian: .unknown, closeOnDeinit: true)
|
||||
let iterator = UnicodeIterator(
|
||||
input: reader.makeUInt8Iterator(),
|
||||
inputEncodingType: codecType
|
||||
)
|
||||
let config = CSVConfiguration(
|
||||
hasHeaderRow: hasHeaderRow,
|
||||
trimFields: trimFields,
|
||||
delimiter: delimiter
|
||||
)
|
||||
try self.init(iterator: iterator, config: config)
|
||||
}
|
||||
|
||||
/// Unavailable.
|
||||
@available(*, unavailable, message: "Use init(stream:codecType:endian:config:) instead")
|
||||
public init<T: UnicodeCodec>(
|
||||
stream: InputStream,
|
||||
codecType: T.Type,
|
||||
endian: Endian = .big,
|
||||
hasHeaderRow: Bool = defaultHasHeaderRow,
|
||||
trimFields: Bool = defaultTrimFields,
|
||||
delimiter: UnicodeScalar = defaultDelimiter
|
||||
) throws where T.CodeUnit == UInt16 {
|
||||
|
||||
let reader = try BinaryReader(stream: stream, endian: endian, closeOnDeinit: true)
|
||||
let iterator = UnicodeIterator(
|
||||
input: reader.makeUInt16Iterator(),
|
||||
inputEncodingType: codecType
|
||||
)
|
||||
let config = CSVConfiguration(
|
||||
hasHeaderRow: hasHeaderRow,
|
||||
trimFields: trimFields,
|
||||
delimiter: delimiter
|
||||
)
|
||||
try self.init(iterator: iterator, config: config)
|
||||
}
|
||||
|
||||
/// Unavailable.
|
||||
@available(*, unavailable, message: "Use init(stream:codecType:endian:config:) instead")
|
||||
public init<T: UnicodeCodec>(
|
||||
stream: InputStream,
|
||||
codecType: T.Type,
|
||||
endian: Endian = .big,
|
||||
hasHeaderRow: Bool = defaultHasHeaderRow,
|
||||
trimFields: Bool = defaultTrimFields,
|
||||
delimiter: UnicodeScalar = defaultDelimiter
|
||||
) throws where T.CodeUnit == UInt32 {
|
||||
|
||||
let reader = try BinaryReader(stream: stream, endian: endian, closeOnDeinit: true)
|
||||
let iterator = UnicodeIterator(
|
||||
input: reader.makeUInt32Iterator(),
|
||||
inputEncodingType: codecType
|
||||
)
|
||||
let config = CSVConfiguration(
|
||||
hasHeaderRow: hasHeaderRow,
|
||||
trimFields: trimFields,
|
||||
delimiter: delimiter
|
||||
)
|
||||
try self.init(iterator: iterator, config: config)
|
||||
}
|
||||
|
||||
/// Unavailable.
|
||||
@available(*, unavailable, message: "Use init(stream:config:) instead")
|
||||
public init(
|
||||
stream: InputStream,
|
||||
hasHeaderRow: Bool = defaultHasHeaderRow,
|
||||
trimFields: Bool = defaultTrimFields,
|
||||
delimiter: UnicodeScalar = defaultDelimiter) throws {
|
||||
|
||||
let config = CSVConfiguration(
|
||||
hasHeaderRow: hasHeaderRow,
|
||||
trimFields: trimFields,
|
||||
delimiter: delimiter
|
||||
)
|
||||
try self.init(stream: stream, codecType: UTF8.self, config: config)
|
||||
}
|
||||
|
||||
/// Unavailable.
|
||||
@available(*, unavailable, message: "Use init(string:config:) instead")
|
||||
public init(
|
||||
string: String,
|
||||
hasHeaderRow: Bool = defaultHasHeaderRow,
|
||||
trimFields: Bool = defaultTrimFields,
|
||||
delimiter: UnicodeScalar = defaultDelimiter) throws {
|
||||
|
||||
let iterator = string.unicodeScalars.makeIterator()
|
||||
let config = CSVConfiguration(
|
||||
hasHeaderRow: hasHeaderRow,
|
||||
trimFields: trimFields,
|
||||
delimiter: delimiter
|
||||
)
|
||||
try self.init(iterator: iterator, config: config)
|
||||
}
|
||||
|
||||
/// Unavailable
|
||||
@available(*, unavailable, message: "Use CSV.Row.subscript(String) instead")
|
||||
public subscript(key: String) -> String? {
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue