mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[stdlib] encode/transcode => [encode/transcode]IfRepresentable...
...to make room for a more useful encode/transcode that inject replacement characters when encoding fails.
This commit is contained in:
@@ -26,11 +26,11 @@ public protocol _UnicodeEncoding {
|
||||
|
||||
/// Converts from encoding-independent to encoded representation, returning
|
||||
/// `nil` if the scalar can't be represented in this encoding.
|
||||
static func encode(_ content: UnicodeScalar) -> EncodedScalar?
|
||||
static func encodeIfRepresentable(_ content: UnicodeScalar) -> EncodedScalar?
|
||||
|
||||
/// Converts a scalar from another encoding's representation, returning
|
||||
/// `nil` if the scalar can't be represented in this encoding.
|
||||
static func transcode<FromEncoding : UnicodeEncoding>(
|
||||
static func transcodeIfRepresentable<FromEncoding : UnicodeEncoding>(
|
||||
_ content: FromEncoding.EncodedScalar, from _: FromEncoding.Type
|
||||
) -> EncodedScalar?
|
||||
|
||||
@@ -55,7 +55,7 @@ public protocol UnicodeEncoding : _UnicodeEncoding
|
||||
where ForwardParser.Encoding == Self, ReverseParser.Encoding == Self {}
|
||||
|
||||
extension _UnicodeEncoding {
|
||||
public static func transcode<FromEncoding : UnicodeEncoding>(
|
||||
public static func transcodeIfRepresentable<FromEncoding : UnicodeEncoding>(
|
||||
_ content: FromEncoding.EncodedScalar, from _: FromEncoding.Type
|
||||
) -> EncodedScalar? {
|
||||
return encode(FromEncoding.decode(content))
|
||||
|
||||
Reference in New Issue
Block a user