mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
11 lines
353 B
Swift
11 lines
353 B
Swift
extension Optional where Wrapped == String {
|
|
/// Executes a closure with a C string pointer, handling nil gracefully.
|
|
func withCString<T>(_ body: (UnsafePointer<Int8>?) throws -> T) rethrows -> T {
|
|
if let string = self {
|
|
return try string.withCString(body)
|
|
} else {
|
|
return try body(nil)
|
|
}
|
|
}
|
|
}
|