Decode nil for single or keyed values if value is 'NA' or 'N/A'

This commit is contained in:
Caleb Kleveter 2018-06-01 09:18:46 -05:00
parent f5940d49e9
commit 60eca9a4cc
No known key found for this signature in database
GPG Key ID: B38DBD5CF2C98D69
2 changed files with 5 additions and 2 deletions

View File

@ -18,7 +18,8 @@ final class _CSVKeyedDecoder<K>: KeyedDecodingContainerProtocol where K: CodingK
}
func decodeNil(forKey key: K) throws -> Bool {
return row[key.stringValue] == nil
let cell = row[key.stringValue]
return cell == nil || cell == Data([.N, .forwardSlash, .A]) || cell == Data([.N, .A])
}
func decode(_ type: Bool.Type, forKey key: K) throws -> Bool {

View File

@ -11,7 +11,9 @@ final class _CSVSingleValueDecoder: SingleValueDecodingContainer {
self.value = value
}
func decodeNil() -> Bool { return self.value == nil }
func decodeNil() -> Bool {
return value == nil || value == Data([.N, .forwardSlash, .A]) || value == Data([.N, .A])
}
func decode(_ type: Bool.Type) throws -> Bool {
guard let cell = self.value else { throw DecodingError.nilValue(type: type, at: self.codingPath) }