1010//
1111//===----------------------------------------------------------------------===//
1212
13- /// Represents a string literal with interpolations while it is being built up.
14- ///
15- /// Do not create an instance of this type directly. It is used by the compiler
16- /// when you create a string using string interpolation. Instead, use string
17- /// interpolation to create a new string by including values, literals,
13+ /// Represents a string literal with interpolations while it's being built up.
14+ ///
15+ /// You don't need to create an instance of this type directly. It's used by the
16+ /// compiler when you create a string using string interpolation. Instead, use
17+ /// string interpolation to create a new string by including values, literals,
1818/// variables, or expressions enclosed in parentheses, prefixed by a
1919/// backslash (`\(`...`)`).
2020///
@@ -68,8 +68,8 @@ public struct DefaultStringInterpolation: StringInterpolationProtocol, Sendable
6868 /// Creates a string interpolation with storage pre-sized for a literal
6969 /// with the indicated attributes.
7070 ///
71- /// Do not call this initializer directly. It is used by the compiler when
72- /// interpreting string interpolations.
71+ /// You don't need to call this initializer directly. It's used by the
72+ /// compiler when interpreting string interpolations.
7373 @inlinable
7474 public init ( literalCapacity: Int , interpolationCount: Int ) {
7575 let capacityPerInterpolation = 2
@@ -80,8 +80,8 @@ public struct DefaultStringInterpolation: StringInterpolationProtocol, Sendable
8080
8181 /// Appends a literal segment of a string interpolation.
8282 ///
83- /// Do not call this method directly. It is used by the compiler when
84- /// interpreting string interpolations.
83+ /// You don't need to call this method directly. It's used by the compiler
84+ /// when interpreting string interpolations.
8585 @inlinable
8686 public mutating func appendLiteral( _ literal: String ) {
8787 literal. write ( to: & self )
@@ -90,8 +90,8 @@ public struct DefaultStringInterpolation: StringInterpolationProtocol, Sendable
9090 /// Interpolates the given value's textual representation into the
9191 /// string literal being created.
9292 ///
93- /// Do not call this method directly. It is used by the compiler when
94- /// interpreting string interpolations. Instead, use string
93+ /// You don't need to call this method directly. It's used by the compiler
94+ /// when interpreting string interpolations. Instead, use string
9595 /// interpolation to create a new string by including values, literals,
9696 /// variables, or expressions enclosed in parentheses, prefixed by a
9797 /// backslash (`\(`...`)`).
@@ -114,8 +114,8 @@ public struct DefaultStringInterpolation: StringInterpolationProtocol, Sendable
114114 /// Interpolates the given value's textual representation into the
115115 /// string literal being created.
116116 ///
117- /// Do not call this method directly. It is used by the compiler when
118- /// interpreting string interpolations. Instead, use string
117+ /// You don't need to call this method directly. It's used by the compiler
118+ /// when interpreting string interpolations. Instead, use string
119119 /// interpolation to create a new string by including values, literals,
120120 /// variables, or expressions enclosed in parentheses, prefixed by a
121121 /// backslash (`\(`...`)`).
@@ -136,8 +136,8 @@ public struct DefaultStringInterpolation: StringInterpolationProtocol, Sendable
136136 /// Interpolates the given value's textual representation into the
137137 /// string literal being created.
138138 ///
139- /// Do not call this method directly. It is used by the compiler when
140- /// interpreting string interpolations. Instead, use string
139+ /// You don't need to call this method directly. It's used by the compiler
140+ /// when interpreting string interpolations. Instead, use string
141141 /// interpolation to create a new string by including values, literals,
142142 /// variables, or expressions enclosed in parentheses, prefixed by a
143143 /// backslash (`\(`...`)`).
@@ -160,8 +160,8 @@ public struct DefaultStringInterpolation: StringInterpolationProtocol, Sendable
160160 /// Interpolates the given value's textual representation into the
161161 /// string literal being created.
162162 ///
163- /// Do not call this method directly. It is used by the compiler when
164- /// interpreting string interpolations. Instead, use string
163+ /// You don't need to call this method directly. It's used by the compiler
164+ /// when interpreting string interpolations. Instead, use string
165165 /// interpolation to create a new string by including values, literals,
166166 /// variables, or expressions enclosed in parentheses, prefixed by a
167167 /// backslash (`\(`...`)`).
@@ -197,6 +197,128 @@ public struct DefaultStringInterpolation: StringInterpolationProtocol, Sendable
197197 }
198198}
199199
200+ extension DefaultStringInterpolation {
201+ /// Interpolates the given optional value's textual representation, or the
202+ /// specified default string, into the string literal being created.
203+ ///
204+ /// You don't need to call this method directly. It's used by the compiler
205+ /// when interpreting string interpolations where you provide a `default`
206+ /// parameter. For example, the following code implicitly calls this method,
207+ /// using the value of the `default` parameter when `value` is `nil`:
208+ ///
209+ /// var age: Int? = 48
210+ /// print("Your age is \(age, default: "unknown")")
211+ /// // Prints: Your age is 48
212+ /// age = nil
213+ /// print("Your age is \(age, default: "unknown")")
214+ /// // Prints: Your age is unknown
215+ ///
216+ /// - Parameters:
217+ /// - value: The value to include in a string interpolation, if non-`nil`.
218+ /// - default: The string to include if `value` is `nil`.
219+ @_alwaysEmitIntoClient
220+ public mutating func appendInterpolation< T> (
221+ _ value: T ? ,
222+ default: @autoclosure ( ) -> some StringProtocol
223+ ) where T: TextOutputStreamable , T: CustomStringConvertible {
224+ if let value {
225+ self . appendInterpolation ( value)
226+ } else {
227+ self . appendInterpolation ( `default` ( ) )
228+ }
229+ }
230+
231+ /// Interpolates the given optional value's textual representation, or the
232+ /// specified default string, into the string literal being created.
233+ ///
234+ /// You don't need to call this method directly. It's used by the compiler
235+ /// when interpreting string interpolations where you provide a `default`
236+ /// parameter. For example, the following code implicitly calls this method,
237+ /// using the value of the `default` parameter when `value` is `nil`:
238+ ///
239+ /// var age: Int? = 48
240+ /// print("Your age is \(age, default: "unknown")")
241+ /// // Prints: Your age is 48
242+ /// age = nil
243+ /// print("Your age is \(age, default: "unknown")")
244+ /// // Prints: Your age is unknown
245+ ///
246+ /// - Parameters:
247+ /// - value: The value to include in a string interpolation, if non-`nil`.
248+ /// - default: The string to include if `value` is `nil`.
249+ @_alwaysEmitIntoClient
250+ public mutating func appendInterpolation< T> (
251+ _ value: T ? ,
252+ default: @autoclosure ( ) -> some StringProtocol
253+ ) where T: TextOutputStreamable {
254+ if let value {
255+ self . appendInterpolation ( value)
256+ } else {
257+ self . appendInterpolation ( `default` ( ) )
258+ }
259+ }
260+
261+ /// Interpolates the given optional value's textual representation, or the
262+ /// specified default string, into the string literal being created.
263+ ///
264+ /// You don't need to call this method directly. It's used by the compiler
265+ /// when interpreting string interpolations where you provide a `default`
266+ /// parameter. For example, the following code implicitly calls this method,
267+ /// using the value of the `default` parameter when `value` is `nil`:
268+ ///
269+ /// var age: Int? = 48
270+ /// print("Your age is \(age, default: "unknown")")
271+ /// // Prints: Your age is 48
272+ /// age = nil
273+ /// print("Your age is \(age, default: "unknown")")
274+ /// // Prints: Your age is unknown
275+ ///
276+ /// - Parameters:
277+ /// - value: The value to include in a string interpolation, if non-`nil`.
278+ /// - default: The string to include if `value` is `nil`.
279+ @_alwaysEmitIntoClient
280+ public mutating func appendInterpolation< T> (
281+ _ value: T ? ,
282+ default: @autoclosure ( ) -> some StringProtocol
283+ ) where T: CustomStringConvertible {
284+ if let value {
285+ self . appendInterpolation ( value)
286+ } else {
287+ self . appendInterpolation ( `default` ( ) )
288+ }
289+ }
290+
291+ /// Interpolates the given optional value's textual representation, or the
292+ /// specified default string, into the string literal being created.
293+ ///
294+ /// You don't need to call this method directly. It's used by the compiler
295+ /// when interpreting string interpolations where you provide a `default`
296+ /// parameter. For example, the following code implicitly calls this method,
297+ /// using the value of the `default` parameter when `value` is `nil`:
298+ ///
299+ /// var age: Int? = 48
300+ /// print("Your age is \(age, default: "unknown")")
301+ /// // Prints: Your age is 48
302+ /// age = nil
303+ /// print("Your age is \(age, default: "unknown")")
304+ /// // Prints: Your age is unknown
305+ ///
306+ /// - Parameters:
307+ /// - value: The value to include in a string interpolation, if non-`nil`.
308+ /// - default: The string to include if `value` is `nil`.
309+ @_alwaysEmitIntoClient
310+ public mutating func appendInterpolation< T> (
311+ _ value: T ? ,
312+ default: @autoclosure ( ) -> some StringProtocol
313+ ) {
314+ if let value {
315+ self . appendInterpolation ( value)
316+ } else {
317+ self . appendInterpolation ( `default` ( ) )
318+ }
319+ }
320+ }
321+
200322extension DefaultStringInterpolation : CustomStringConvertible {
201323 @inlinable
202324 public var description : String {
@@ -220,9 +342,9 @@ extension DefaultStringInterpolation: TextOutputStream {
220342extension String {
221343 /// Creates a new instance from an interpolated string literal.
222344 ///
223- /// Do not call this initializer directly. It is used by the compiler when
224- /// you create a string using string interpolation. Instead, use string
225- /// interpolation to create a new string by including values, literals,
345+ /// You don't need to call this initializer directly. It's used by the
346+ /// compiler when you create a string using string interpolation. Instead, use
347+ /// string interpolation to create a new string by including values, literals,
226348 /// variables, or expressions enclosed in parentheses, prefixed by a
227349 /// backslash (`\(`...`)`).
228350 ///
@@ -244,9 +366,9 @@ extension String {
244366extension Substring {
245367 /// Creates a new instance from an interpolated string literal.
246368 ///
247- /// Do not call this initializer directly. It is used by the compiler when
248- /// you create a string using string interpolation. Instead, use string
249- /// interpolation to create a new string by including values, literals,
369+ /// You don't need to call this initializer directly. It's used by the
370+ /// compiler when you create a string using string interpolation. Instead, use
371+ /// string interpolation to create a new string by including values, literals,
250372 /// variables, or expressions enclosed in parentheses, prefixed by a
251373 /// backslash (`\(`...`)`).
252374 ///
0 commit comments