Revert "[cxx-interop] Add conversions between std::u16string and Swift.String"

This commit is contained in:
Egor Zhdan
2022-10-26 11:54:39 +01:00
committed by GitHub
parent 4573dd6d7b
commit e97b1c8e5b
2 changed files with 0 additions and 59 deletions

View File

@@ -10,8 +10,6 @@
//
//===----------------------------------------------------------------------===//
// MARK: Initializing C++ string from a Swift String
extension std.string {
public init(_ string: String) {
self.init()
@@ -21,31 +19,12 @@ extension std.string {
}
}
extension std.u16string {
public init(_ string: String) {
self.init()
for char in string.utf16 {
self.push_back(char)
}
}
}
// MARK: Initializing C++ string from a Swift String literal
extension std.string: ExpressibleByStringLiteral {
public init(stringLiteral value: String) {
self.init(value)
}
}
extension std.u16string: ExpressibleByStringLiteral {
public init(stringLiteral value: String) {
self.init(value)
}
}
// MARK: Initializing Swift String from a C++ string
extension String {
public init(cxxString: std.string) {
let buffer = UnsafeBufferPointer<CChar>(
@@ -56,12 +35,4 @@ extension String {
}
withExtendedLifetime(cxxString) {}
}
public init(cxxU16String: std.u16string) {
let buffer = UnsafeBufferPointer<UInt16>(
start: cxxU16String.__dataUnsafe(),
count: cxxU16String.size())
self = String(decoding: buffer, as: UTF16.self)
withExtendedLifetime(cxxU16String) {}
}
}

View File

@@ -37,36 +37,6 @@ StdStringOverlayTestSuite.test("std::string <=> Swift.String") {
expectEqual(swift6, "xyz\0abc")
}
StdStringOverlayTestSuite.test("std::u16string <=> Swift.String") {
let cxx1 = std.u16string()
let swift1 = String(cxxU16String: cxx1)
expectEqual(swift1, "")
let cxx2 = std.u16string("something123")
expectEqual(cxx2.size(), 12)
let swift2 = String(cxxU16String: cxx2)
expectEqual(swift2, "something123")
let cxx3: std.u16string = "literal"
expectEqual(cxx3.size(), 7)
let cxx4: std.u16string = "тест"
expectEqual(cxx4.size(), 4)
let swift4 = String(cxxU16String: cxx4)
expectEqual(swift4, "тест")
// Emojis are represented by more than one CWideChar.
let cxx5: std.u16string = "emoji_🤖"
expectEqual(cxx5.size(), 8)
let swift5 = String(cxxU16String: cxx5)
expectEqual(swift5, "emoji_🤖")
let cxx6 = std.u16string("xyz\0abc")
expectEqual(cxx6.size(), 7)
let swift6 = String(cxxU16String: cxx6)
expectEqual(swift6, "xyz\0abc")
}
extension std.string.const_iterator: UnsafeCxxInputIterator {
// This func should not be required.
public static func ==(lhs: std.string.const_iterator,