File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
test/Interop/Cxx/stdlib/overlay Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,12 @@ extension std.string: ExpressibleByStringLiteral {
27
27
28
28
extension String {
29
29
public init ( cxxString: std . string ) {
30
- self . init ( cString: cxxString. __c_strUnsafe ( ) )
30
+ let buffer = UnsafeBufferPointer < CChar > (
31
+ start: cxxString. __c_strUnsafe ( ) ,
32
+ count: cxxString. size ( ) )
33
+ self = buffer. withMemoryRebound ( to: UInt8 . self) {
34
+ String ( decoding: $0, as: UTF8 . self)
35
+ }
31
36
withExtendedLifetime ( cxxString) { }
32
37
}
33
38
}
Original file line number Diff line number Diff line change @@ -30,6 +30,11 @@ StdStringOverlayTestSuite.test("std::string <=> Swift.String") {
30
30
expectEqual ( cxx5. size ( ) , 10 )
31
31
let swift5 = String ( cxxString: cxx5)
32
32
expectEqual ( swift5, " emoji_🤖 " )
33
+
34
+ let cxx6 = std. string ( " xyz \0 abc " )
35
+ expectEqual ( cxx6. size ( ) , 7 )
36
+ let swift6 = String ( cxxString: cxx6)
37
+ expectEqual ( swift6, " xyz \0 abc " )
33
38
}
34
39
35
40
extension std . string . const_iterator : UnsafeCxxInputIterator {
You can’t perform that action at this time.
0 commit comments