mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-12 02:59:45 +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: a3e6856b56
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
|
@_exported import AKCxx
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public extension Foundation.Data {
|
extension Swift.String {
|
||||||
init(_ string: AK.StringView) {
|
public init?(akString: AK.String) {
|
||||||
let bytes = string.bytes()
|
let bytes = akString.__bytes_as_string_viewUnsafe().bytes()
|
||||||
self.init(bytesNoCopy: UnsafeMutableRawPointer(mutating: bytes.data()), count: bytes.size(), deallocator: .none)
|
let data = Foundation.Data(bytesNoCopy: UnsafeMutableRawPointer(mutating: bytes.data()), count: bytes.size(), deallocator: .none)
|
||||||
}
|
|
||||||
|
self.init(data: data, encoding: .utf8)
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension Swift.String {
|
public init?(akStringView: AK.StringView) {
|
||||||
init?(_ string: AK.String) {
|
let bytes = akStringView.bytes()
|
||||||
self.init(data: Foundation.Data(string.__bytes_as_string_viewUnsafe()), encoding: .utf8)
|
let data = Foundation.Data(bytesNoCopy: UnsafeMutableRawPointer(mutating: bytes.data()), count: bytes.size(), deallocator: .none)
|
||||||
}
|
|
||||||
|
|
||||||
init?(_ string: AK.StringView) {
|
self.init(data: data, encoding: .utf8)
|
||||||
self.init(data: Foundation.Data(string), encoding: .utf8)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ private func hexNibblesToUInt8(_ nib1: Character, _ nib2: Character) -> UInt8? {
|
||||||
|
|
||||||
// FIXME: Return Gfx.Color? When swift ABI bug is fixed
|
// FIXME: Return Gfx.Color? When swift ABI bug is fixed
|
||||||
public func parseHexString(_ rawString: AK.StringView) -> [Gfx.Color] {
|
public func parseHexString(_ rawString: AK.StringView) -> [Gfx.Color] {
|
||||||
guard let string = Swift.String(rawString) else {
|
guard let string = Swift.String(akStringView: rawString) else {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ extension Swift.String {
|
||||||
public init?(decoding: AK.StringView, as: AK.StringView) {
|
public init?(decoding: AK.StringView, as: AK.StringView) {
|
||||||
let maybe_decoded = Web.HTML.decode_to_utf8(decoding, `as`)
|
let maybe_decoded = Web.HTML.decode_to_utf8(decoding, `as`)
|
||||||
if maybe_decoded.hasValue {
|
if maybe_decoded.hasValue {
|
||||||
self.init(maybe_decoded.value!)
|
self.init(akString: maybe_decoded.value!)
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue