2024-08-23 18:22:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2024-08-27 01:04:05 +00:00
|
|
|
@_exported import AKCxx
|
2024-08-23 18:22:26 +00:00
|
|
|
import Foundation
|
|
|
|
|
2024-08-29 03:17:25 +00:00
|
|
|
extension Swift.String {
|
|
|
|
public init?(akString: AK.String) {
|
|
|
|
let bytes = akString.__bytes_as_string_viewUnsafe().bytes()
|
|
|
|
let data = Foundation.Data(bytesNoCopy: UnsafeMutableRawPointer(mutating: bytes.data()), count: bytes.size(), deallocator: .none)
|
2024-08-23 18:22:26 +00:00
|
|
|
|
2024-08-29 03:17:25 +00:00
|
|
|
self.init(data: data, encoding: .utf8)
|
2024-08-23 18:22:26 +00:00
|
|
|
}
|
|
|
|
|
2024-08-29 03:17:25 +00:00
|
|
|
public init?(akStringView: AK.StringView) {
|
|
|
|
let bytes = akStringView.bytes()
|
|
|
|
let data = Foundation.Data(bytesNoCopy: UnsafeMutableRawPointer(mutating: bytes.data()), count: bytes.size(), deallocator: .none)
|
|
|
|
|
|
|
|
self.init(data: data, encoding: .utf8)
|
2024-08-23 18:22:26 +00:00
|
|
|
}
|
|
|
|
}
|
2024-08-29 03:22:05 +00:00
|
|
|
|
|
|
|
extension AK.StringView: ExpressibleByStringLiteral {
|
|
|
|
public typealias StringLiteralType = Swift.StaticString
|
|
|
|
|
|
|
|
public init(stringLiteral value: StringLiteralType) {
|
|
|
|
self.init(value.utf8Start, value.utf8CodeUnitCount)
|
|
|
|
}
|
|
|
|
}
|