@@ -42,7 +42,8 @@ extension String {
42
42
/// }
43
43
/// // Prints "Caf�"
44
44
///
45
- /// - Parameter nullTerminatedUTF8: A pointer to a null-terminated UTF-8 code sequence.
45
+ /// - Parameter nullTerminatedUTF8:
46
+ /// A pointer to a null-terminated sequence of UTF-8 code units.
46
47
public init ( cString nullTerminatedUTF8: UnsafePointer < CChar > ) {
47
48
let len = UTF8 . _nullCodeUnitOffset ( in: nullTerminatedUTF8)
48
49
let buffer = UnsafeBufferPointer ( start: nullTerminatedUTF8, count: len)
@@ -92,6 +93,9 @@ extension String {
92
93
///
93
94
/// This is identical to `init(cString: UnsafePointer<CChar>)` but operates on
94
95
/// an unsigned sequence of bytes.
96
+ ///
97
+ /// - Parameter nullTerminatedUTF8:
98
+ /// A pointer to a null-terminated sequence of UTF-8 code units.
95
99
public init ( cString nullTerminatedUTF8: UnsafePointer < UInt8 > ) {
96
100
let len = UTF8 . _nullCodeUnitOffset ( in: nullTerminatedUTF8)
97
101
self = String . _fromUTF8Repairing (
@@ -152,7 +156,7 @@ extension String {
152
156
/// // Prints "nil"
153
157
///
154
158
/// - Parameter nullTerminatedUTF8:
155
- /// A pointer to a null-terminated UTF-8 code sequence .
159
+ /// A pointer to a null-terminated sequence of UTF-8 code units .
156
160
@inlinable
157
161
@_alwaysEmitIntoClient
158
162
public init ? ( validatingCString nullTerminatedUTF8: UnsafePointer < CChar > ) {
@@ -185,10 +189,11 @@ extension String {
185
189
/// }
186
190
/// // Prints "nil"
187
191
///
188
- /// Note: This initializer is deprecated . Use
192
+ /// Note: This initializer has been renamed . Use
189
193
/// `String.init?(validatingCString:)` instead.
190
194
///
191
- /// - Parameter cString: A pointer to a null-terminated UTF-8 code sequence.
195
+ /// - Parameter cString:
196
+ /// A pointer to a null-terminated sequence of UTF-8 code units.
192
197
@available ( swift, deprecated: 6 , renamed: " String.init(validatingCString:) " )
193
198
public init ? ( validatingUTF8 cString: UnsafePointer < CChar > ) {
194
199
let len = UTF8 . _nullCodeUnitOffset ( in: cString)
@@ -287,8 +292,8 @@ extension String {
287
292
/// // Prints "Optional((result: "Caf�", repairsMade: true))"
288
293
///
289
294
/// - Parameters:
290
- /// - cString: A pointer to a null-terminated code sequence encoded in
291
- /// `encoding`.
295
+ /// - cString: A pointer to a null-terminated sequence of
296
+ /// code units encoded in `encoding`.
292
297
/// - encoding: The Unicode encoding of the data referenced by `cString`.
293
298
/// - isRepairing: Pass `true` to create a new string, even when the data
294
299
/// referenced by `cString` contains ill-formed sequences. Ill-formed
@@ -397,13 +402,16 @@ extension String {
397
402
return ( " " , false )
398
403
}
399
404
400
- /// Creates a string from the null-terminated sequence of bytes at the given
401
- /// pointer.
405
+ /// Creates a new string by copying the null-terminated sequence of code units
406
+ /// referenced by the given pointer.
407
+ ///
408
+ /// If `nullTerminatedCodeUnits` contains ill-formed code unit sequences, this
409
+ /// initializer replaces them with the Unicode replacement character
410
+ /// (`"\u{FFFD}"`).
402
411
///
403
412
/// - Parameters:
404
- /// - nullTerminatedCodeUnits: A pointer to a sequence of contiguous code
405
- /// units in the encoding specified in `sourceEncoding`, ending just
406
- /// before the first zero code unit.
413
+ /// - nullTerminatedCodeUnits: A pointer to a null-terminated sequence of
414
+ /// code units encoded in `sourceEncoding`.
407
415
/// - sourceEncoding: The encoding in which the code units should be
408
416
/// interpreted.
409
417
@_specialize ( where Encoding == Unicode. UTF8 )
0 commit comments