From 458167935c770bf0a29dda4b7b70caa3c0f60762 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sat, 16 Nov 2024 14:24:06 -0700 Subject: [PATCH] AK: Add an extension to construct an AK.String from a Swift.String --- AK/AK+Swift.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/AK/AK+Swift.swift b/AK/AK+Swift.swift index 4f13f29f5db..6fa270dd239 100644 --- a/AK/AK+Swift.swift +++ b/AK/AK+Swift.swift @@ -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