[stdlib] String initialization with encoding and CString interop

This commit is contained in:
Dave Abrahams
2017-05-08 19:50:38 -07:00
parent cb5b5bad7c
commit fd8cfea3ac
5 changed files with 284 additions and 40 deletions

View File

@@ -62,13 +62,15 @@ extension _UnicodeEncoding {
}
/// Converts from encoding-independent to encoded representation, returning
/// `nil` if the scalar can't be represented in this encoding.
/// `encodedReplacementCharacter` if the scalar can't be represented in this
/// encoding.
public static func encode(_ content: UnicodeScalar) -> EncodedScalar {
return encodeIfRepresentable(content) ?? encodedReplacementCharacter
}
/// Converts a scalar from another encoding's representation, returning
/// `nil` if the scalar can't be represented in this encoding.
/// `encodedReplacementCharacter` if the scalar can't be represented in this
/// encoding.
public static func transcode<FromEncoding : UnicodeEncoding>(
_ content: FromEncoding.EncodedScalar, from _: FromEncoding.Type
) -> EncodedScalar {