mirror of
https://github.com/apple/swift-system
synced 2026-11-23 04:34:26 +00:00
This brings the contents of this package up to date with versions of the ABI stable `System` module that shipped in recent iOS/macOS releases. Most changes only touch internal implementation details, but some ABI-related fixes also affect the public API. There are no source-incompatible changes. - ABI stability fixes (un-deprecate CModeT, don't use PlatformChar in inlinable contexts that need to deploy to iOS 14) - New utilities: `_RawBuffer`, `Array<String>._withCStringArray`, `_withOptionalUnsafePointerOrNull`, `_withStackBuffer`, `system_memset` - Prefer using explicit optionals to implicitly-unwrapped ones - Add support for wildcard matching in mocking tests - A bunch of new availability annotations. (I expect there will be more of these coming in future PRs.)
30 lines
840 B
Swift
30 lines
840 B
Swift
/*
|
|
This source file is part of the Swift System open source project
|
|
|
|
Copyright (c) 2021 Apple Inc. and the Swift System project authors
|
|
Licensed under Apache License v2.0 with Runtime Library Exception
|
|
|
|
See https://swift.org/LICENSE.txt for license information
|
|
*/
|
|
|
|
extension String {
|
|
internal init(
|
|
_unsafeUninitializedCapacity capacity: Int,
|
|
initializingUTF8With body: (UnsafeMutableBufferPointer<UInt8>) throws -> Int
|
|
) rethrows {
|
|
if #available(macOS 11, iOS 14.0, watchOS 7.0, tvOS 14.0, *) {
|
|
self = try String(
|
|
unsafeUninitializedCapacity: capacity,
|
|
initializingUTF8With: body)
|
|
return
|
|
}
|
|
|
|
let array = try Array<UInt8>(
|
|
unsafeUninitializedCapacity: capacity
|
|
) { buffer, count in
|
|
count = try body(buffer)
|
|
}
|
|
self = String(decoding: array, as: UTF8.self)
|
|
}
|
|
}
|