Skip to content

Commit

Permalink
just use String instead of StringProtocol for pre-5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
tejassharma96 committed Apr 1, 2024
1 parent b2ed94e commit 6ef2b9e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Sources/Yams/Encoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,30 @@ extension _Encoder: SingleValueEncodingContainer {
func encode<T>(_ value: T) throws where T: YAMLEncodable {
assertCanEncodeNewValue()
node = value.box()
#if swift(>=5.6)
if let stringValue = value as? (any StringProtocol), stringValue.contains("\n") {
node.scalar?.style = newlineScalarStyle
}
#else
if let stringValue = value as? String, stringValue.contains("\n") {
node.scalar?.style = newlineScalarStyle
}
#endif
}

func encode<T>(_ value: T) throws where T: Encodable {
assertCanEncodeNewValue()
if let encodable = value as? YAMLEncodable {
node = encodable.box()
#if swift(>=5.6)
if let stringValue = value as? (any StringProtocol), stringValue.contains("\n") {
node.scalar?.style = newlineScalarStyle
}
#else
if let stringValue = value as? String, stringValue.contains("\n") {
node.scalar?.style = newlineScalarStyle
}
#endif
} else {
try value.encode(to: self)
}
Expand Down

0 comments on commit 6ef2b9e

Please sign in to comment.