AK: Add an extension to construct an AK.String from a Swift.String

This commit is contained in:
Andrew Kaster 2024-11-16 14:24:06 -07:00 committed by Andrew Kaster
parent a95f761cb4
commit 458167935c
Notes: github-actions[bot] 2024-11-19 21:54:54 +00:00

View file

@ -23,6 +23,14 @@ extension Swift.String {
}
}
extension AK.String {
public init(swiftString: consuming Swift.String) {
self.init() // Create empty string first, using default constructor
swiftString.withUTF8 { buffer in
self = AK.String.from_utf8_without_validation(AK.ReadonlyBytes(buffer.baseAddress!, buffer.count))
}
}
}
extension AK.StringView: ExpressibleByStringLiteral {
public typealias StringLiteralType = Swift.StaticString