@@ -72,6 +72,18 @@ extension String {
72
72
) . 0
73
73
}
74
74
75
+ @inlinable
76
+ @_alwaysEmitIntoClient
77
+ @available ( * , deprecated)
78
+ public init ( cString nullTerminatedUTF8: inout CChar ) {
79
+ guard nullTerminatedUTF8 == 0 else {
80
+ _preconditionFailure (
81
+ " input of String.init(cString:) must be null-terminated "
82
+ )
83
+ }
84
+ self = " "
85
+ }
86
+
75
87
/// Creates a new string by copying the null-terminated UTF-8 data referenced
76
88
/// by the given pointer.
77
89
///
@@ -98,6 +110,18 @@ extension String {
98
110
self = nullTerminatedUTF8. withCString ( String . init ( cString: ) )
99
111
}
100
112
113
+ @inlinable
114
+ @_alwaysEmitIntoClient
115
+ @available ( * , deprecated)
116
+ public init ( cString nullTerminatedUTF8: inout UInt8 ) {
117
+ guard nullTerminatedUTF8 == 0 else {
118
+ _preconditionFailure (
119
+ " input of String.init(cString:) must be null-terminated "
120
+ )
121
+ }
122
+ self = " "
123
+ }
124
+
101
125
/// Creates a new string by copying and validating the null-terminated UTF-8
102
126
/// data referenced by the given pointer.
103
127
///
@@ -155,6 +179,18 @@ extension String {
155
179
self = cString. withCString ( String . init ( cString: ) )
156
180
}
157
181
182
+ @inlinable
183
+ @_alwaysEmitIntoClient
184
+ @available ( * , deprecated)
185
+ public init ? ( validatingUTF8 cString: inout CChar ) {
186
+ guard cString == 0 else {
187
+ _preconditionFailure (
188
+ " input of String.init(validatingUTF8:) must be null-terminated "
189
+ )
190
+ }
191
+ self = " "
192
+ }
193
+
158
194
/// Creates a new string by copying the null-terminated data referenced by
159
195
/// the given pointer using the specified encoding.
160
196
///
@@ -279,6 +315,24 @@ extension String {
279
315
}
280
316
}
281
317
318
+ @_specialize ( where Encoding == Unicode. UTF8 )
319
+ @_specialize ( where Encoding == Unicode. UTF16 )
320
+ @inlinable
321
+ @_alwaysEmitIntoClient
322
+ @available ( * , deprecated)
323
+ public static func decodeCString< Encoding: _UnicodeEncoding > (
324
+ _ cString: inout Encoding . CodeUnit ,
325
+ as encoding: Encoding . Type ,
326
+ repairingInvalidCodeUnits isRepairing: Bool = true
327
+ ) -> ( result: String , repairsMade: Bool ) ? {
328
+ guard cString == 0 else {
329
+ _preconditionFailure (
330
+ " input of decodeCString(_:as:repairingInvalidCodeUnits:) must be null-terminated "
331
+ )
332
+ }
333
+ return ( " " , false )
334
+ }
335
+
282
336
/// Creates a string from the null-terminated sequence of bytes at the given
283
337
/// pointer.
284
338
///
@@ -322,6 +376,22 @@ extension String {
322
376
String ( decodingCString: $0, as: sourceEncoding. self)
323
377
}
324
378
}
379
+
380
+ @_specialize ( where Encoding == Unicode. UTF8 )
381
+ @_specialize ( where Encoding == Unicode. UTF16 )
382
+ @inlinable // Fold away specializations
383
+ @_alwaysEmitIntoClient
384
+ public init < Encoding: Unicode . Encoding > (
385
+ decodingCString nullTerminatedCodeUnits: inout Encoding . CodeUnit ,
386
+ as sourceEncoding: Encoding . Type
387
+ ) {
388
+ guard nullTerminatedCodeUnits == 0 else {
389
+ _preconditionFailure (
390
+ " input of String.init(decodingCString:as:) must be null-terminated "
391
+ )
392
+ }
393
+ self = " "
394
+ }
325
395
}
326
396
327
397
extension UnsafePointer where Pointee == UInt8 {
0 commit comments