Add support for Display String type to StructuredFieldValues (#51)

Motivation:

The parser and serializer for the Display String type have been
implemented. The high-level encoder and decoder should follow.

Modifications:

Implement the encoder and decoder for Display String.

Result:

The StructuredFieldValues module will support the Display String type.

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
This commit is contained in:
Clinton NkwochaandCory Benfield authored and GitHub committed 2024-12-10 07:56:51 +00:00
1 parent 0d92bf6b08
commit be84570e9f
13 files changed
+292 -43

No files matched your search

@@ -141,6 +141,14 @@ extension BareItemDecoder: SingleValueDecodingContainer {
return Date(timeIntervalSince1970: Double(date))
}
func decode(_: DisplayString.Type) throws -> DisplayString {
guard case .displayString(let string) = self.item else {
throw StructuredHeaderError.invalidTypeForItem
}
return DisplayString(rawValue: string)
}
func decodeNil() -> Bool {
// Items are never nil.
false
@@ -182,6 +190,8 @@ extension BareItemDecoder: SingleValueDecodingContainer {
return try self.decode(Decimal.self) as! T
case is Date.Type:
return try self.decode(Date.self) as! T
case is DisplayString.Type:
return try self.decode(DisplayString.self) as! T
default:
throw StructuredHeaderError.invalidTypeForItem
}