Skip to content

Commit 55a02ab

Browse files
committed
[stdlib] rename validatingUTF8 to validatingCString properly
#68433 was fixed in commit d19f082.
1 parent e10899e commit 55a02ab

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

stdlib/public/core/CString.swift

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,16 @@ 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 validated = nullTerminatedUTF8.withMemoryRebound(
193+
to: UInt8.self,
194+
capacity: len,
195+
{ String._tryFromUTF8(UnsafeBufferPointer(start: $0, count: len)) }
196+
)
197+
guard let validated else { return nil }
198+
self = validated
194199
}
195200

196201
/// Creates a new string by copying and validating the null-terminated UTF-8
@@ -223,15 +228,12 @@ extension String {
223228
///
224229
/// - Parameter cString:
225230
/// A pointer to a null-terminated sequence of UTF-8 code units.
231+
@inlinable
232+
@_alwaysEmitIntoClient
226233
@available(swift, deprecated: 6, renamed: "String.init(validatingCString:)")
234+
@_silgen_name("_swift_se0405_String_validatingUTF8")
227235
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
236+
self.init(validatingCString: cString)
235237
}
236238

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

0 commit comments

Comments
 (0)