mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[stdlib] UnicodeEncoding: hide/internalize APIs we're not sure about
The best high-level APIs for decoding/transcoding are still under active investigation. It's likely we want more views. Therefore, leave de-underscored/public only the lowest-level APIs for now.
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 encodeIfRepresentable(_ content: UnicodeScalar) -> EncodedScalar?
|
||||
static func encode(_ 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 transcodeIfRepresentable<FromEncoding : UnicodeEncoding>(
|
||||
static func transcode<FromEncoding : UnicodeEncoding>(
|
||||
_ content: FromEncoding.EncodedScalar, from _: FromEncoding.Type
|
||||
) -> EncodedScalar?
|
||||
|
||||
@@ -55,25 +55,25 @@ public protocol UnicodeEncoding : _UnicodeEncoding
|
||||
where ForwardParser.Encoding == Self, ReverseParser.Encoding == Self {}
|
||||
|
||||
extension _UnicodeEncoding {
|
||||
public static func transcodeIfRepresentable<FromEncoding : UnicodeEncoding>(
|
||||
public static func transcode<FromEncoding : UnicodeEncoding>(
|
||||
_ content: FromEncoding.EncodedScalar, from _: FromEncoding.Type
|
||||
) -> EncodedScalar? {
|
||||
return encodeIfRepresentable(FromEncoding.decode(content))
|
||||
return encode(FromEncoding.decode(content))
|
||||
}
|
||||
|
||||
/// Converts from encoding-independent to encoded representation, returning
|
||||
/// `encodedReplacementCharacter` if the scalar can't be represented in this
|
||||
/// encoding.
|
||||
public static func encode(_ content: UnicodeScalar) -> EncodedScalar {
|
||||
return encodeIfRepresentable(content) ?? encodedReplacementCharacter
|
||||
internal static func _encode(_ content: UnicodeScalar) -> EncodedScalar {
|
||||
return encode(content) ?? encodedReplacementCharacter
|
||||
}
|
||||
|
||||
/// Converts a scalar from another encoding's representation, returning
|
||||
/// `encodedReplacementCharacter` if the scalar can't be represented in this
|
||||
/// encoding.
|
||||
public static func transcode<FromEncoding : UnicodeEncoding>(
|
||||
internal static func _transcode<FromEncoding : UnicodeEncoding>(
|
||||
_ content: FromEncoding.EncodedScalar, from _: FromEncoding.Type
|
||||
) -> EncodedScalar {
|
||||
return encode(FromEncoding.decode(content))
|
||||
return _encode(FromEncoding.decode(content))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user