Skip to content

Commit 048a948

Browse files
committed
[stdlib] document some deprecated initializers
1 parent e3ede3a commit 048a948

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

stdlib/public/core/CString.swift

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ extension String {
5252
}
5353
}
5454

55+
/// Creates a new string by copying the null-terminated UTF-8 data referenced
56+
/// by the given array.
57+
///
58+
/// If `cString` contains ill-formed UTF-8 code unit sequences, this
59+
/// initializer replaces them with the Unicode replacement character
60+
/// (`"\u{FFFD}"`).
61+
///
62+
/// Note: This initializer is deprecated. Use the initializer
63+
/// `String.init(decoding: array, as: UTF8.self)` instead,
64+
/// remembering that "\0" is a valid character in Swift.
65+
///
66+
/// - Parameter nullTerminatedUTF8:
67+
/// An array containing a null-terminated sequence of UTF-8 code units.
5568
@inlinable
5669
@_alwaysEmitIntoClient
5770
@available(swift, deprecated: 6, message: "Use String(decoding: array, as: UTF8.self) instead")
@@ -102,6 +115,18 @@ extension String {
102115
UnsafeBufferPointer(start: nullTerminatedUTF8, count: len)).0
103116
}
104117

118+
/// Creates a new string by copying the null-terminated UTF-8 data referenced
119+
/// by the given array.
120+
///
121+
/// This is identical to `init(cString: [CChar])` but operates on
122+
/// an unsigned sequence of bytes.
123+
///
124+
/// Note: This initializer is deprecated. Use the initializer
125+
/// `String.init(decoding: array, as: UTF8.self)` instead,
126+
/// remembering that "\0" is a valid character in Swift.
127+
///
128+
/// - Parameter nullTerminatedUTF8:
129+
/// An array containing a null-terminated UTF-8 code unit sequence.
105130
@inlinable
106131
@_alwaysEmitIntoClient
107132
@available(swift, deprecated: 6, message: "Use String(decoding: array, as: UTF8.self) instead")
@@ -205,6 +230,18 @@ extension String {
205230
self = str
206231
}
207232

233+
/// Creates a new string by copying and validating the null-terminated UTF-8
234+
/// data referenced by the given array.
235+
///
236+
/// This initializer does not try to repair ill-formed UTF-8 code unit
237+
/// sequences. If any are found, the result of the initializer is `nil`.
238+
///
239+
/// Note: This initializer is deprecated. Use the initializer
240+
/// `String.init?(validating: array, as: UTF8.self)` instead,
241+
/// remembering that "\0" is a valid character in Swift.
242+
///
243+
/// - Parameter nullTerminatedUTF8:
244+
/// An array containing a null-terminated sequence of UTF-8 code units.
208245
@inlinable
209246
@_alwaysEmitIntoClient
210247
@available(swift, deprecated: 6, message: "Use String(validating: array, as: UTF8.self) instead")
@@ -221,6 +258,18 @@ extension String {
221258
self = string
222259
}
223260

261+
/// Creates a new string by copying and validating the null-terminated UTF-8
262+
/// data referenced by the given array.
263+
///
264+
/// This initializer does not try to repair ill-formed UTF-8 code unit
265+
/// sequences. If any are found, the result of the initializer is `nil`.
266+
///
267+
/// Note: This initializer is deprecated. Use the initializer
268+
/// `String.init?(validating: array, as: UTF8.self)` instead,
269+
/// remembering that "\0" is a valid character in Swift.
270+
///
271+
/// - Parameter cString:
272+
/// An array containing a null-terminated sequence of UTF-8 code units.
224273
@inlinable
225274
@_alwaysEmitIntoClient
226275
@available(swift, deprecated: 6, message: "Use String(validating: array, as: UTF8.self) instead")
@@ -424,6 +473,22 @@ extension String {
424473
self = String.decodeCString(nullTerminatedCodeUnits, as: sourceEncoding)!.0
425474
}
426475

476+
/// Creates a new string by copying the null-terminated sequence of code units
477+
/// referenced by the given array.
478+
///
479+
/// If `nullTerminatedCodeUnits` contains ill-formed code unit sequences, this
480+
/// initializer replaces them with the Unicode replacement character
481+
/// (`"\u{FFFD}"`).
482+
///
483+
/// Note: This initializer is deprecated. Use the initializer
484+
/// `String.init(decoding: array, as: Encoding.self)` instead,
485+
/// remembering that "\0" is a valid character in Swift.
486+
///
487+
/// - Parameters:
488+
/// - nullTerminatedCodeUnits: An array containing a null-terminated
489+
/// sequence of code units encoded in `sourceEncoding`.
490+
/// - sourceEncoding: The encoding in which the code units should be
491+
/// interpreted.
427492
@inlinable
428493
@_alwaysEmitIntoClient
429494
@available(swift, deprecated: 6, message: "Use String(decoding: array, as: Encoding.self) instead")

0 commit comments

Comments
 (0)