Skip to content

Commit d4b732b

Browse files
committed
Add CustomStringConvertible to LocalPart
- LocalPart now conforms to CustomStringConvertible with description property - Enables direct string interpolation without explicit .stringValue - More idiomatic Swift API
1 parent 060f6d4 commit d4b732b

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

Sources/RFC_5322/RFC 5322.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,13 @@ extension RFC_5322.EmailAddress {
143143
}
144144

145145
/// The string representation
146-
public var stringValue: String {
146+
public var description: String {
147147
switch storage {
148148
case .dotAtom(let string), .quoted(let string):
149149
return string
150150
}
151151
}
152152

153-
/// Description for CustomStringConvertible
154-
public var description: String { stringValue }
155-
156153
// swiftlint:disable:next nesting
157154
private enum Storage: Hashable {
158155
case dotAtom(String) // Regular unquoted format
@@ -188,14 +185,14 @@ extension RFC_5322.EmailAddress {
188185
!$0.isLetter && !$0.isNumber && !$0.isWhitespace || $0.asciiValue == nil
189186
})
190187
let quotedName = needsQuoting ? "\"\(name)\"" : name
191-
return "\(quotedName) <\(localPart.stringValue)@\(domain.name)>" // Exactly one space before angle bracket
188+
return "\(quotedName) <\(localPart)@\(domain.name)>" // Exactly one space before angle bracket
192189
}
193-
return "\(localPart.stringValue)@\(domain.name)"
190+
return "\(localPart)@\(domain.name)"
194191
}
195192

196193
/// Just the email address part without display name
197194
public var addressValue: String {
198-
"\(localPart.stringValue)@\(domain.name)"
195+
"\(localPart)@\(domain.name)"
199196
}
200197
}
201198

0 commit comments

Comments
 (0)