mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
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`.
This commit is contained in:
parent
03bbc2b111
commit
a3e6856b56
Notes:
github-actions[bot]
2024-08-29 04:32:23 +00:00
Author: https://github.com/ADKaster Commit: https://github.com/LadybirdBrowser/ladybird/commit/a3e6856b569 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1220
3 changed files with 12 additions and 13 deletions
|
@ -7,19 +7,18 @@
|
|||
@_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)
|
||||
}
|
||||
}
|
||||
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)
|
||||
|
||||
public extension Swift.String {
|
||||
init?(_ string: AK.String) {
|
||||
self.init(data: Foundation.Data(string.__bytes_as_string_viewUnsafe()), encoding: .utf8)
|
||||
self.init(data: data, encoding: .utf8)
|
||||
}
|
||||
|
||||
init?(_ string: AK.StringView) {
|
||||
self.init(data: Foundation.Data(string), 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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ private func hexNibblesToUInt8(_ nib1: Character, _ nib2: Character) -> UInt8? {
|
|||
|
||||
// FIXME: Return Gfx.Color? When swift ABI bug is fixed
|
||||
public func parseHexString(_ rawString: AK.StringView) -> [Gfx.Color] {
|
||||
guard let string = Swift.String(rawString) else {
|
||||
guard let string = Swift.String(akStringView: rawString) else {
|
||||
return []
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ extension Swift.String {
|
|||
public init?(decoding: AK.StringView, as: AK.StringView) {
|
||||
let maybe_decoded = Web.HTML.decode_to_utf8(decoding, `as`)
|
||||
if maybe_decoded.hasValue {
|
||||
self.init(maybe_decoded.value!)
|
||||
self.init(akString: maybe_decoded.value!)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue