Skip to content

Commit f61a4bd

Browse files
authored
Merge pull request swiftlang#62945 from apple/egorzhdan/cxx-string-docs
[cxx-interop] NFC: Add documentation comments for string conversion
2 parents e2842c7 + fb27f39 commit f61a4bd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

stdlib/public/Cxx/std/String.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
extension std.string {
14+
/// Creates a C++ string having the same content as the given Swift string.
15+
///
16+
/// - Complexity: O(*n*), where *n* is the number of UTF-8 code units in the
17+
/// Swift string.
1418
public init(_ string: String) {
1519
self.init()
1620
for char in string.utf8 {
@@ -26,6 +30,13 @@ extension std.string: ExpressibleByStringLiteral {
2630
}
2731

2832
extension String {
33+
/// Creates a String having the same content as the given C++ string.
34+
///
35+
/// If `cxxString` contains ill-formed UTF-8 code unit sequences, this
36+
/// initializer replaces them with the Unicode replacement character
37+
/// (`"\u{FFFD}"`).
38+
///
39+
/// - Complexity: O(*n*), where *n* is the number of bytes in the C++ string.
2940
public init(cxxString: std.string) {
3041
let buffer = UnsafeBufferPointer<CChar>(
3142
start: cxxString.__c_strUnsafe(),

0 commit comments

Comments
 (0)