Files
ladybird/AK/AK+Swift.swift
Andrew Kaster c5153cb398 Meta+Libraries+AK: Append Cxx to imported library module names in swift
At the same time, simplify CMakeLists magic for libraries that want to
include Swift code in the library. The Lib-less name of the library is
now always the module name for the library with any Swift additions,
extensions, etc. All vfs overlays now live in a common location to make
finding them easier from CMake functions. A new pattern is needed for
the Lib-less modules to re-export their Cxx counterparts.
2024-08-27 17:22:31 -06:00

26 lines
673 B
Swift

/*
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@_exported import AKCxx
import Foundation
public extension Foundation.Data {
init(_ string: AK.StringView) {
let bytes = string.bytes()
self.init(bytesNoCopy: UnsafeMutableRawPointer(mutating: bytes.data()), count: bytes.size(), deallocator: .none)
}
}
public extension Swift.String {
init?(_ string: AK.String) {
self.init(data: Foundation.Data(string.__bytes_as_string_viewUnsafe()), encoding: .utf8)
}
init?(_ string: AK.StringView) {
self.init(data: Foundation.Data(string), encoding: .utf8)
}
}