From 42beb847f5e04d75aeb0d81e62c347e419b3de1b Mon Sep 17 00:00:00 2001 From: Glenn Wood Date: Wed, 28 Apr 2021 19:16:31 -0400 Subject: [PATCH] Fix itsy-bitsy-teenie-tiny flaw in CSwiftV(with: "") --- Sources/CSwiftV.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/CSwiftV.swift b/Sources/CSwiftV.swift index 50f8326..70f9283 100644 --- a/Sources/CSwiftV.swift +++ b/Sources/CSwiftV.swift @@ -38,8 +38,8 @@ public class CSwiftV { /// - Parameter headers: The array of headers from the file. If not included, it will be populated with the ones from the first line public init(with string: String, separator: String = ",", headers: [String]? = nil) { - var parsedLines = CSwiftV.records(from: string.replacingOccurrences(of: "\r\n", with: "\n")).map { CSwiftV.cells(forRow: $0, separator: separator) } - self.headers = headers ?? parsedLines.removeFirst() + var parsedLines = CSwiftV.records(from: string.replacingOccurrences(of: "\r\n", with: "\n")).map({ CSwiftV.cells(forRow: $0, separator: separator) }) + self.headers = parsedLines.count == 0 ? [] : (headers ?? parsedLines.removeFirst()) rows = parsedLines columnCount = self.headers.count @@ -105,3 +105,4 @@ public class CSwiftV { } } +