mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Revert "[cxx-interop] Add conversions between std::u16string and Swift.String"
This commit is contained in:
@@ -10,8 +10,6 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
// MARK: Initializing C++ string from a Swift String
|
|
||||||
|
|
||||||
extension std.string {
|
extension std.string {
|
||||||
public init(_ string: String) {
|
public init(_ string: String) {
|
||||||
self.init()
|
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 {
|
extension std.string: ExpressibleByStringLiteral {
|
||||||
public init(stringLiteral value: String) {
|
public init(stringLiteral value: String) {
|
||||||
self.init(value)
|
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 {
|
extension String {
|
||||||
public init(cxxString: std.string) {
|
public init(cxxString: std.string) {
|
||||||
let buffer = UnsafeBufferPointer<CChar>(
|
let buffer = UnsafeBufferPointer<CChar>(
|
||||||
@@ -56,12 +35,4 @@ extension String {
|
|||||||
}
|
}
|
||||||
withExtendedLifetime(cxxString) {}
|
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) {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,36 +37,6 @@ StdStringOverlayTestSuite.test("std::string <=> Swift.String") {
|
|||||||
expectEqual(swift6, "xyz\0abc")
|
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 {
|
extension std.string.const_iterator: UnsafeCxxInputIterator {
|
||||||
// This func should not be required.
|
// This func should not be required.
|
||||||
public static func ==(lhs: std.string.const_iterator,
|
public static func ==(lhs: std.string.const_iterator,
|
||||||
|
|||||||
Reference in New Issue
Block a user