Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitribouniol committed Apr 18, 2021
1 parent b3789f8 commit ee0b74b
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Sources/DynamicCodable/DynamicCodableDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ extension DynamicCodableDecoder.Decoder: Swift.Decoder {
is Primitive.UInt32.Type,
is Primitive.UInt64.Type,
is Primitive.Empty.Type: return try value.unwrap { throw error }
// Special Cases
// case is Date.Type: return unwrapDate() as! T
// case is Data.Type: return unwrapData() as! T
// case is URL.Type: return unwrapURL() as! T
// case is Decimal.Type: return unwrapDecimal() as! T
// case is _JSONStringDictionaryDecodableMarker.Type: return unwrapDictionary(as: T.self) as! T
// Decodable Types
default: return try T(from: self)
}
Expand All @@ -150,6 +156,7 @@ extension DynamicCodableDecoder.Decoder: Swift.Decoder {
return floatingPoint
}

// may want to support both strict numeric checks as well as loose numeric checks (used below).
switch representation {
case .float64(let number): return try validate(T(number), originalValue: number)
case .float32(let number): return try validate(T(number), originalValue: number)
Expand All @@ -164,6 +171,17 @@ extension DynamicCodableDecoder.Decoder: Swift.Decoder {
case .uint32(let number): return try validate(T(number), originalValue: number)
case .uint64(let number): return try validate(T(number), originalValue: number)

// case .string(let string):
// if case .convertFromString(let posInfString, let negInfString, let nanString) = self.options.nonConformingFloatDecodingStrategy {
// if string == posInfString {
// return T.infinity
// } else if string == negInfString {
// return -T.infinity
// } else if string == nanString {
// return T.nan
// }
// }
//
case .string,
.bool,
.keyed,
Expand All @@ -190,6 +208,7 @@ extension DynamicCodableDecoder.Decoder: Swift.Decoder {
return fixedWidthInteger
}

// may want to support both strict numeric checks as well as loose numeric checks (used below).
switch representation {
case .int(let number): return try validate(T(exactly: number), originalValue: number)
case .int8(let number): return try validate(T(exactly: number), originalValue: number)
Expand Down Expand Up @@ -231,6 +250,39 @@ extension DynamicCodableDecoder.Decoder {

var codingPath: [CodingKey] { decoder.codingPath }

// init(
// decoder: DynamicCodableDecoder.Decoder,
// codingPath: [CodingKey],
// representation: [DynamicCodable.Key : DynamicCodable]
// ) {
// self.decoder = decoder
// self.codingPath = codingPath
//
//// switch impl.options.keyDecodingStrategy {
//// case .useDefaultKeys:
//// self.dictionary = dictionary
//// case .convertFromSnakeCase:
//// // Convert the snake case keys in the container to camel case.
//// // If we hit a duplicate key after conversion, then we'll use the first one we saw.
//// // Effectively an undefined behavior with JSON dictionaries.
//// var converted = [String: JSONValue]()
//// converted.reserveCapacity(dictionary.count)
//// dictionary.forEach { (key, value) in
//// converted[JSONDecoder.KeyDecodingStrategy._convertFromSnakeCase(key)] = value
//// }
//// self.dictionary = converted
//// case .custom(let converter):
//// var converted = [String: JSONValue]()
//// converted.reserveCapacity(dictionary.count)
//// dictionary.forEach { (key, value) in
//// var pathForKey = codingPath
//// pathForKey.append(_JSONKey(stringValue: key)!)
//// converted[converter(pathForKey).stringValue] = value
//// }
//// self.dictionary = converted
//// }
// }

var allKeys: [Key] {
representation.keys.compactMap { dynamicKey in
switch dynamicKey {
Expand Down

0 comments on commit ee0b74b

Please sign in to comment.