File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,20 @@ extension _UnicodeEncoding {
58
58
public static func transcodeIfRepresentable< FromEncoding : UnicodeEncoding > (
59
59
_ content: FromEncoding . EncodedScalar , from _: FromEncoding . Type
60
60
) -> EncodedScalar ? {
61
+ return encodeIfRepresentable ( FromEncoding . decode ( content) )
62
+ }
63
+
64
+ /// Converts from encoding-independent to encoded representation, returning
65
+ /// `nil` if the scalar can't be represented in this encoding.
66
+ static func encode( _ content: UnicodeScalar ) -> EncodedScalar {
67
+ return encodeIfRepresentable ( content) ?? encodedReplacementCharacter
68
+ }
69
+
70
+ /// Converts a scalar from another encoding's representation, returning
71
+ /// `nil` if the scalar can't be represented in this encoding.
72
+ static func transcode< FromEncoding : UnicodeEncoding > (
73
+ _ content: FromEncoding . EncodedScalar , from _: FromEncoding . Type
74
+ ) -> EncodedScalar {
61
75
return encode ( FromEncoding . decode ( content) )
62
76
}
63
77
}
You can’t perform that action at this time.
0 commit comments