ladybird/AK/AK+Swift.swift
Andrew Kaster a3e6856b56 AK+Swift: Remove Foundation.Data footgun for AK.StringView
Also give the Swift.String init routines an explict label when
constructing from AK String types, as this caused issues in a later
commit to have them both with `_ data`.
2024-08-29 06:31:25 +02:00

24 lines
766 B
Swift

/*
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@_exported import AKCxx
import Foundation
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)
self.init(data: data, encoding: .utf8)
}
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)
}
}