Skip to content

Commit 3ee901d

Browse files
committed
[stdlib] rename validatingUTF8 to validatingCString properly
In commit d19f082, #68433 was fixed.
1 parent e10899e commit 3ee901d

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

stdlib/public/core/CString.swift

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,17 @@ extension String {
186186
///
187187
/// - Parameter nullTerminatedUTF8:
188188
/// A pointer to a null-terminated sequence of UTF-8 code units.
189-
@inlinable
190-
@_alwaysEmitIntoClient
189+
@_silgen_name("$sSS14validatingUTF8SSSgSPys4Int8VG_tcfC")
191190
public init?(validatingCString nullTerminatedUTF8: UnsafePointer<CChar>) {
192-
// FIXME: https://github.com/apple/swift/issues/68433 (rdar://115296219)
193-
self.init(validatingUTF8: nullTerminatedUTF8)
191+
let len = UTF8._nullCodeUnitOffset(in: nullTerminatedUTF8)
192+
let str = nullTerminatedUTF8.withMemoryRebound(
193+
to: UInt8.self,
194+
capacity: len,
195+
{ String._tryFromUTF8(UnsafeBufferPointer(start: $0, count: len)) }
196+
)
197+
guard let str else { return nil }
198+
199+
self = str
194200
}
195201

196202
/// Creates a new string by copying and validating the null-terminated UTF-8
@@ -223,15 +229,12 @@ extension String {
223229
///
224230
/// - Parameter cString:
225231
/// A pointer to a null-terminated sequence of UTF-8 code units.
232+
@inlinable
233+
@_alwaysEmitIntoClient
226234
@available(swift, deprecated: 6, renamed: "String.init(validatingCString:)")
235+
@_silgen_name("_swift_se0405_String_validatingUTF8")
227236
public init?(validatingUTF8 cString: UnsafePointer<CChar>) {
228-
let len = UTF8._nullCodeUnitOffset(in: cString)
229-
guard let str = cString.withMemoryRebound(to: UInt8.self, capacity: len, {
230-
String._tryFromUTF8(UnsafeBufferPointer(start: $0, count: len))
231-
})
232-
else { return nil }
233-
234-
self = str
237+
self.init(validatingCString: cString)
235238
}
236239

237240
/// Creates a new string by copying and validating the null-terminated UTF-8

0 commit comments

Comments
 (0)