Skip to content

Commit 1e9ef94

Browse files
committed
better naming
1 parent 5fab234 commit 1e9ef94

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

Sources/AWSLambdaEvents/Utils/DateWrappers.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ public struct RFC5322DateTimeCoding: Decodable, Sendable {
117117

118118
do {
119119
if #available(macOS 12.0, *) {
120-
self.wrappedValue = try Date(string, strategy: RFC5322DateStrategy())
120+
self.wrappedValue = try Date(string, strategy: RFC5322DateParseStrategy())
121121
} else {
122-
self.wrappedValue = try RFC5322DateStrategy().parse(string)
122+
self.wrappedValue = try RFC5322DateParseStrategy().parse(string)
123123
}
124124
} catch {
125125
throw DecodingError.dataCorruptedError(
@@ -133,7 +133,7 @@ public struct RFC5322DateTimeCoding: Decodable, Sendable {
133133

134134
struct RFC5322DateParsingError: Error {}
135135

136-
struct RFC5322DateStrategy {
136+
struct RFC5322DateParseStrategy {
137137
func parse(_ input: String) throws -> Date {
138138
guard let components = self.components(from: input) else {
139139
throw RFC5322DateParsingError()
@@ -152,17 +152,17 @@ struct RFC5322DateStrategy {
152152
}
153153
var s = input[input.startIndex..<endIndex]
154154

155-
let asciiNumbers = UInt8(ascii: "0")...UInt8(ascii: "9")
155+
let asciiDigits = UInt8(ascii: "0")...UInt8(ascii: "9")
156156

157157
return s.withUTF8 { buffer -> DateComponents? in
158158
func parseDay(_ it: inout UnsafeBufferPointer<UInt8>.Iterator) -> Int? {
159159
let first = it.next()
160160
let second = it.next()
161161
guard let first = first, let second = second else { return nil }
162162

163-
guard asciiNumbers.contains(first) else { return nil }
163+
guard asciiDigits.contains(first) else { return nil }
164164

165-
if asciiNumbers.contains(second) {
165+
if asciiDigits.contains(second) {
166166
return Int(first - UInt8(ascii: "0")) * 10 + Int(second - UInt8(ascii: "0"))
167167
} else {
168168
return Int(first - UInt8(ascii: "0"))
@@ -188,10 +188,10 @@ struct RFC5322DateStrategy {
188188
}
189189

190190
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()
195195
guard let first = first,
196196
let second = second,
197197
let third = third,
@@ -204,22 +204,22 @@ struct RFC5322DateStrategy {
204204
}
205205

206206
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()
209209
guard let first = first, let second = second else { return nil }
210210
return Int(first - UInt8(ascii: "0")) * 10 + Int(second - UInt8(ascii: "0"))
211211
}
212212

213213
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()
216216
guard let first = first, let second = second else { return nil }
217217
return Int(first - UInt8(ascii: "0")) * 10 + Int(second - UInt8(ascii: "0"))
218218
}
219219

220220
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()
223223
guard let first = first, let second = second else { return nil }
224224
return Int(first - UInt8(ascii: "0")) * 10 + Int(second - UInt8(ascii: "0"))
225225
}
@@ -281,7 +281,7 @@ struct RFC5322DateStrategy {
281281
}
282282

283283
@available(macOS 12.0, *)
284-
extension RFC5322DateStrategy: ParseStrategy {}
284+
extension RFC5322DateParseStrategy: ParseStrategy {}
285285

286286
extension IteratorProtocol where Self.Element == UInt8 {
287287
mutating func expect(_ expected: UInt8) -> Bool {
@@ -298,7 +298,7 @@ extension IteratorProtocol where Self.Element == UInt8 {
298298
return nil
299299
}
300300

301-
mutating func nextAsciiNumber(skippingWhitespace: Bool = false) -> UInt8? {
301+
mutating func nextAsciiDigit(skippingWhitespace: Bool = false) -> UInt8? {
302302
while let c = self.next() {
303303
if skippingWhitespace {
304304
if c == UInt8(ascii: " ") {

0 commit comments

Comments
 (0)