Skip to content

Commit 12675dd

Browse files
authored
Merge pull request #78540 from glessard/string-gardening
2 parents b0bb19c + d4ae6b0 commit 12675dd

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

stdlib/public/core/LifetimeManager.swift

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -253,28 +253,6 @@ public func _withUnprotectedUnsafePointer<
253253
return try body(UnsafePointer<T>(Builtin.unprotectedAddressOfBorrow(value)))
254254
}
255255

256-
extension String {
257-
/// Calls the given closure with a pointer to the contents of the string,
258-
/// represented as a null-terminated sequence of UTF-8 code units.
259-
///
260-
/// The pointer passed as an argument to `body` is valid only during the
261-
/// execution of `withCString(_:)`. Do not store or return the pointer for
262-
/// later use.
263-
///
264-
/// - Parameter body: A closure with a pointer parameter that points to a
265-
/// null-terminated sequence of UTF-8 code units. If `body` has a return
266-
/// value, that value is also used as the return value for the
267-
/// `withCString(_:)` method. The pointer argument is valid only for the
268-
/// duration of the method's execution.
269-
/// - Returns: The return value, if any, of the `body` closure parameter.
270-
@inlinable // fast-path: already C-string compatible
271-
public func withCString<Result>(
272-
_ body: (UnsafePointer<Int8>) throws -> Result
273-
) rethrows -> Result {
274-
return try _guts.withCString(body)
275-
}
276-
}
277-
278256
@available(*, deprecated, message: "Use the copy operator")
279257
@_alwaysEmitIntoClient
280258
@inlinable

stdlib/public/core/String.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,26 @@ extension String {
681681
initializingWith: initializer)
682682
}
683683

684+
/// Calls the given closure with a pointer to the contents of the string,
685+
/// represented as a null-terminated sequence of UTF-8 code units.
686+
///
687+
/// The pointer passed as an argument to `body` is valid only during the
688+
/// execution of `withCString(_:)`. Do not store or return the pointer for
689+
/// later use.
690+
///
691+
/// - Parameter body: A closure with a pointer parameter that points to a
692+
/// null-terminated sequence of UTF-8 code units. If `body` has a return
693+
/// value, that value is also used as the return value for the
694+
/// `withCString(_:)` method. The pointer argument is valid only for the
695+
/// duration of the method's execution.
696+
/// - Returns: The return value, if any, of the `body` closure parameter.
697+
@inlinable // fast-path: already C-string compatible
698+
public func withCString<Result>(
699+
_ body: (UnsafePointer<Int8>) throws -> Result
700+
) rethrows -> Result {
701+
return try _guts.withCString(body)
702+
}
703+
684704
/// Calls the given closure with a pointer to the contents of the string,
685705
/// represented as a null-terminated sequence of code units.
686706
///

0 commit comments

Comments
 (0)