@@ -18,8 +18,6 @@ import FoundationEssentials
1818import Foundation
1919#endif
2020
21-
22-
2321@propertyWrapper
2422public struct ISO8601Coding : Decodable , Sendable {
2523 public let wrappedValue : Date
@@ -31,7 +29,7 @@ public struct ISO8601Coding: Decodable, Sendable {
3129 public init ( from decoder: Decoder ) throws {
3230 let container = try decoder. singleValueContainer ( )
3331 let dateString = try container. decode ( String . self)
34-
32+
3533 struct InvalidDateError : Error { }
3634
3735 do {
@@ -125,9 +123,9 @@ public struct RFC5322DateTimeCoding: Decodable, Sendable {
125123 }
126124 } catch {
127125 throw DecodingError . dataCorruptedError (
128- in: container,
129- debugDescription:
130- " Expected date to be in RFC5322 date-time format, but ` \( string) ` is not in the correct format "
126+ in: container,
127+ debugDescription:
128+ " Expected date to be in RFC5322 date-time format, but ` \( string) ` is not in the correct format "
131129 )
132130 }
133131 }
@@ -151,17 +149,17 @@ struct RFC5322DateStrategy {
151149 // If the date string has a timezone in brackets, we need to remove it before parsing.
152150 if let bracket = input. firstIndex ( of: " ( " ) {
153151 endIndex = bracket
154- }
152+ }
155153 var s = input [ input. startIndex..< endIndex]
156154
157- let asciiNumbers = UInt8 ( ascii: " 0 " ) ... UInt8 ( ascii: " 9 " )
155+ let asciiNumbers = UInt8 ( ascii: " 0 " ) ... UInt8 ( ascii: " 9 " )
158156
159157 return s. withUTF8 { buffer -> DateComponents ? in
160158 func parseDay( _ it: inout UnsafeBufferPointer < UInt8 > . Iterator ) -> Int ? {
161159 let first = it. next ( )
162160 let second = it. next ( )
163161 guard let first = first, let second = second else { return nil }
164-
162+
165163 guard asciiNumbers. contains ( first) else { return nil }
166164
167165 if asciiNumbers. contains ( second) {
@@ -185,7 +183,7 @@ struct RFC5322DateStrategy {
185183 let second = it. nextAsciiLetter ( )
186184 let third = it. nextAsciiLetter ( )
187185 guard let first = first, let second = second, let third = third else { return nil }
188- guard first. isAsciiLetter else { return nil }
186+ guard first. isAsciiLetter else { return nil }
189187 return monthMap [ [ first, second, third] ]
190188 }
191189
@@ -194,8 +192,14 @@ struct RFC5322DateStrategy {
194192 let second = it. nextAsciiNumber ( )
195193 let third = it. nextAsciiNumber ( )
196194 let fourth = it. nextAsciiNumber ( )
197- guard let first = first, let second = second, let third = third, let fourth = fourth else { return nil }
198- return Int ( first - UInt8( ascii: " 0 " ) ) * 1000 + Int( second - UInt8( ascii: " 0 " ) ) * 100 + Int( third - UInt8( ascii: " 0 " ) ) * 10 + Int( fourth - UInt8( ascii: " 0 " ) )
195+ guard let first = first,
196+ let second = second,
197+ let third = third,
198+ let fourth = fourth else { return nil }
199+ return Int ( first - UInt8( ascii: " 0 " ) ) * 1000
200+ + Int( second - UInt8( ascii: " 0 " ) ) * 100
201+ + Int( third - UInt8( ascii: " 0 " ) ) * 10
202+ + Int( fourth - UInt8( ascii: " 0 " ) )
199203 }
200204
201205 func parseHour( _ it: inout UnsafeBufferPointer < UInt8 > . Iterator ) -> Int ? {
@@ -242,7 +246,7 @@ struct RFC5322DateStrategy {
242246
243247 // if the 4th character is a comma, then we have a day of the week
244248 guard buffer. count > 5 else { return nil }
245-
249+
246250 if buffer [ 3 ] == UInt8 ( ascii: " , " ) {
247251 for _ in 0 ..< 5 {
248252 _ = it. next ( )
@@ -276,7 +280,7 @@ struct RFC5322DateStrategy {
276280}
277281
278282@available ( macOS 12 . 0 , * )
279- extension RFC5322DateStrategy : ParseStrategy { }
283+ extension RFC5322DateStrategy : ParseStrategy { }
280284
281285extension IteratorProtocol where Self. Element == UInt8 {
282286 mutating func expect( _ expected: UInt8 ) -> Bool {
@@ -301,8 +305,8 @@ extension IteratorProtocol where Self.Element == UInt8 {
301305 }
302306 }
303307 switch c {
304- case UInt8 ( ascii: " 0 " ) ... UInt8 ( ascii: " 9 " ) : return c
305- default : return nil
308+ case UInt8 ( ascii: " 0 " ) ... UInt8 ( ascii: " 9 " ) : return c
309+ default : return nil
306310 }
307311 }
308312 return nil
@@ -317,9 +321,10 @@ extension IteratorProtocol where Self.Element == UInt8 {
317321 }
318322
319323 switch c {
320- case UInt8 ( ascii: " A " ) ... UInt8 ( ascii: " Z " ) ,
321- UInt8 ( ascii: " a " ) ... UInt8 ( ascii: " z " ) : return c
322- default : return nil
324+ case UInt8 ( ascii: " A " ) ... UInt8 ( ascii: " Z " ) ,
325+ UInt8 ( ascii: " a " ) ... UInt8 ( ascii: " z " ) :
326+ return c
327+ default : return nil
323328 }
324329 }
325330 return nil
@@ -329,19 +334,30 @@ extension IteratorProtocol where Self.Element == UInt8 {
329334extension UInt8 {
330335 var isAsciiLetter : Bool {
331336 switch self {
332- case UInt8 ( ascii: " A " ) ... UInt8 ( ascii: " Z " ) ,
333- UInt8 ( ascii: " a " ) ... UInt8 ( ascii: " z " ) : return true
334- default : return false
337+ case UInt8 ( ascii: " A " ) ... UInt8 ( ascii: " Z " ) ,
338+ UInt8 ( ascii: " a " ) ... UInt8 ( ascii: " z " ) :
339+ return true
340+ default : return false
335341 }
336342 }
337343}
338344
339- let monthMap : [ Array < UInt8 > : Int ] = [
340- Array ( " Jan " . utf8) : 1 , Array ( " Feb " . utf8) : 2 , Array ( " Mar " . utf8) : 3 , Array ( " Apr " . utf8) : 4 , Array ( " May " . utf8) : 5 , Array ( " Jun " . utf8) : 6 ,
341- Array ( " Jul " . utf8) : 7 , Array ( " Aug " . utf8) : 8 , Array ( " Sep " . utf8) : 9 , Array ( " Oct " . utf8) : 10 , Array ( " Nov " . utf8) : 11 , Array ( " Dec " . utf8) : 12
345+ let monthMap : [ [ UInt8 ] : Int ] = [
346+ Array ( " Jan " . utf8) : 1 ,
347+ Array ( " Feb " . utf8) : 2 ,
348+ Array ( " Mar " . utf8) : 3 ,
349+ Array ( " Apr " . utf8) : 4 ,
350+ Array ( " May " . utf8) : 5 ,
351+ Array ( " Jun " . utf8) : 6 ,
352+ Array ( " Jul " . utf8) : 7 ,
353+ Array ( " Aug " . utf8) : 8 ,
354+ Array ( " Sep " . utf8) : 9 ,
355+ Array ( " Oct " . utf8) : 10 ,
356+ Array ( " Nov " . utf8) : 11 ,
357+ Array ( " Dec " . utf8) : 12 ,
342358]
343359
344- let timezoneOffsetMap : [ Array < UInt8 > : Int ] = [
360+ let timezoneOffsetMap : [ [ UInt8 ] : Int ] = [
345361 Array ( " UTC " . utf8) : 0 ,
346362 Array ( " GMT " . utf8) : 0 ,
347363 Array ( " EDT " . utf8) : - 4 * 60 ,
0 commit comments