@@ -91,6 +91,13 @@ extension String {
91
91
}
92
92
}
93
93
94
+ @inlinable
95
+ @_alwaysEmitIntoClient
96
+ @available ( * , deprecated, message: " Operate directly on the String " )
97
+ public init ( cString nullTerminatedUTF8: String ) {
98
+ self = nullTerminatedUTF8. withCString ( String . init ( cString: ) )
99
+ }
100
+
94
101
/// Creates a new string by copying and validating the null-terminated UTF-8
95
102
/// data referenced by the given pointer.
96
103
///
@@ -141,6 +148,13 @@ extension String {
141
148
self = string
142
149
}
143
150
151
+ @inlinable
152
+ @_alwaysEmitIntoClient
153
+ @available ( * , deprecated, message: " Operate directly on the String " )
154
+ public init ? ( validatingUTF8 cString: String ) {
155
+ self = cString. withCString ( String . init ( cString: ) )
156
+ }
157
+
144
158
/// Creates a new string by copying the null-terminated data referenced by
145
159
/// the given pointer using the specified encoding.
146
160
///
@@ -248,6 +262,23 @@ extension String {
248
262
}
249
263
}
250
264
265
+ @_specialize ( where Encoding == Unicode. UTF8 )
266
+ @_specialize ( where Encoding == Unicode. UTF16 )
267
+ @inlinable
268
+ @_alwaysEmitIntoClient
269
+ @available ( * , deprecated, message: " Operate directly on the String " )
270
+ public static func decodeCString< Encoding: _UnicodeEncoding > (
271
+ _ cString: String ,
272
+ as encoding: Encoding . Type ,
273
+ repairingInvalidCodeUnits isRepairing: Bool = true
274
+ ) -> ( result: String , repairsMade: Bool ) ? {
275
+ return cString. withCString ( encodedAs: encoding) {
276
+ String . decodeCString (
277
+ $0, as: encoding, repairingInvalidCodeUnits: isRepairing
278
+ )
279
+ }
280
+ }
281
+
251
282
/// Creates a string from the null-terminated sequence of bytes at the given
252
283
/// pointer.
253
284
///
@@ -277,6 +308,20 @@ extension String {
277
308
) {
278
309
self = String . decodeCString ( nullTerminatedCodeUnits, as: sourceEncoding) !. 0
279
310
}
311
+
312
+ @_specialize ( where Encoding == Unicode. UTF8 )
313
+ @_specialize ( where Encoding == Unicode. UTF16 )
314
+ @inlinable
315
+ @_alwaysEmitIntoClient
316
+ @available ( * , deprecated, message: " Operate directly on the String " )
317
+ public init < Encoding: _UnicodeEncoding > (
318
+ decodingCString nullTerminatedCodeUnits: String ,
319
+ as sourceEncoding: Encoding . Type
320
+ ) {
321
+ self = nullTerminatedCodeUnits. withCString ( encodedAs: sourceEncoding) {
322
+ String ( decodingCString: $0, as: sourceEncoding. self)
323
+ }
324
+ }
280
325
}
281
326
282
327
extension UnsafePointer where Pointee == UInt8 {
0 commit comments