@@ -117,9 +117,9 @@ public struct RFC5322DateTimeCoding: Decodable, Sendable {
117
117
118
118
do {
119
119
if #available( macOS 12 . 0 , * ) {
120
- self . wrappedValue = try Date ( string, strategy: RFC5322DateStrategy ( ) )
120
+ self . wrappedValue = try Date ( string, strategy: RFC5322DateParseStrategy ( ) )
121
121
} else {
122
- self . wrappedValue = try RFC5322DateStrategy ( ) . parse ( string)
122
+ self . wrappedValue = try RFC5322DateParseStrategy ( ) . parse ( string)
123
123
}
124
124
} catch {
125
125
throw DecodingError . dataCorruptedError (
@@ -133,7 +133,7 @@ public struct RFC5322DateTimeCoding: Decodable, Sendable {
133
133
134
134
struct RFC5322DateParsingError : Error { }
135
135
136
- struct RFC5322DateStrategy {
136
+ struct RFC5322DateParseStrategy {
137
137
func parse( _ input: String ) throws -> Date {
138
138
guard let components = self . components ( from: input) else {
139
139
throw RFC5322DateParsingError ( )
@@ -152,17 +152,17 @@ struct RFC5322DateStrategy {
152
152
}
153
153
var s = input [ input. startIndex..< endIndex]
154
154
155
- let asciiNumbers = UInt8 ( ascii: " 0 " ) ... UInt8 ( ascii: " 9 " )
155
+ let asciiDigits = UInt8 ( ascii: " 0 " ) ... UInt8 ( ascii: " 9 " )
156
156
157
157
return s. withUTF8 { buffer -> DateComponents ? in
158
158
func parseDay( _ it: inout UnsafeBufferPointer < UInt8 > . Iterator ) -> Int ? {
159
159
let first = it. next ( )
160
160
let second = it. next ( )
161
161
guard let first = first, let second = second else { return nil }
162
162
163
- guard asciiNumbers . contains ( first) else { return nil }
163
+ guard asciiDigits . contains ( first) else { return nil }
164
164
165
- if asciiNumbers . contains ( second) {
165
+ if asciiDigits . contains ( second) {
166
166
return Int ( first - UInt8( ascii: " 0 " ) ) * 10 + Int( second - UInt8( ascii: " 0 " ) )
167
167
} else {
168
168
return Int ( first - UInt8( ascii: " 0 " ) )
@@ -188,10 +188,10 @@ struct RFC5322DateStrategy {
188
188
}
189
189
190
190
func parseYear( _ it: inout UnsafeBufferPointer < UInt8 > . Iterator ) -> Int ? {
191
- let first = it. nextAsciiNumber ( skippingWhitespace: true )
192
- let second = it. nextAsciiNumber ( )
193
- let third = it. nextAsciiNumber ( )
194
- let fourth = it. nextAsciiNumber ( )
191
+ let first = it. nextAsciiDigit ( skippingWhitespace: true )
192
+ let second = it. nextAsciiDigit ( )
193
+ let third = it. nextAsciiDigit ( )
194
+ let fourth = it. nextAsciiDigit ( )
195
195
guard let first = first,
196
196
let second = second,
197
197
let third = third,
@@ -204,22 +204,22 @@ struct RFC5322DateStrategy {
204
204
}
205
205
206
206
func parseHour( _ it: inout UnsafeBufferPointer < UInt8 > . Iterator ) -> Int ? {
207
- let first = it. nextAsciiNumber ( skippingWhitespace: true )
208
- let second = it. nextAsciiNumber ( )
207
+ let first = it. nextAsciiDigit ( skippingWhitespace: true )
208
+ let second = it. nextAsciiDigit ( )
209
209
guard let first = first, let second = second else { return nil }
210
210
return Int ( first - UInt8( ascii: " 0 " ) ) * 10 + Int( second - UInt8( ascii: " 0 " ) )
211
211
}
212
212
213
213
func parseMinute( _ it: inout UnsafeBufferPointer < UInt8 > . Iterator ) -> Int ? {
214
- let first = it. nextAsciiNumber ( skippingWhitespace: true )
215
- let second = it. nextAsciiNumber ( )
214
+ let first = it. nextAsciiDigit ( skippingWhitespace: true )
215
+ let second = it. nextAsciiDigit ( )
216
216
guard let first = first, let second = second else { return nil }
217
217
return Int ( first - UInt8( ascii: " 0 " ) ) * 10 + Int( second - UInt8( ascii: " 0 " ) )
218
218
}
219
219
220
220
func parseSecond( _ it: inout UnsafeBufferPointer < UInt8 > . Iterator ) -> Int ? {
221
- let first = it. nextAsciiNumber ( skippingWhitespace: true )
222
- let second = it. nextAsciiNumber ( )
221
+ let first = it. nextAsciiDigit ( skippingWhitespace: true )
222
+ let second = it. nextAsciiDigit ( )
223
223
guard let first = first, let second = second else { return nil }
224
224
return Int ( first - UInt8( ascii: " 0 " ) ) * 10 + Int( second - UInt8( ascii: " 0 " ) )
225
225
}
@@ -281,7 +281,7 @@ struct RFC5322DateStrategy {
281
281
}
282
282
283
283
@available ( macOS 12 . 0 , * )
284
- extension RFC5322DateStrategy : ParseStrategy { }
284
+ extension RFC5322DateParseStrategy : ParseStrategy { }
285
285
286
286
extension IteratorProtocol where Self. Element == UInt8 {
287
287
mutating func expect( _ expected: UInt8 ) -> Bool {
@@ -298,7 +298,7 @@ extension IteratorProtocol where Self.Element == UInt8 {
298
298
return nil
299
299
}
300
300
301
- mutating func nextAsciiNumber ( skippingWhitespace: Bool = false ) -> UInt8 ? {
301
+ mutating func nextAsciiDigit ( skippingWhitespace: Bool = false ) -> UInt8 ? {
302
302
while let c = self . next ( ) {
303
303
if skippingWhitespace {
304
304
if c == UInt8 ( ascii: " " ) {
0 commit comments