|
1 | | -//===--- StringInterpolation.swift.gyb - String Interpolation -*- swift -*-===// |
| 1 | +//===--- StringInterpolation.swift - String Interpolation -----*- swift -*-===// |
2 | 2 | // |
3 | 3 | // This source file is part of the Swift.org open source project |
4 | 4 | // |
|
10 | 10 | // |
11 | 11 | //===----------------------------------------------------------------------===// |
12 | 12 |
|
13 | | -%{ |
14 | | - |
15 | | -from SwiftIntTypes import all_integer_types |
16 | | - |
17 | | -# Number of bits in the Builtin.Word type |
18 | | -word_bits = int(CMAKE_SIZEOF_VOID_P) * 8 |
19 | | - |
20 | | -StreamableTypes = [ |
21 | | - 'String', |
22 | | - 'Character', |
23 | | - 'UnicodeScalar', |
24 | | - ] |
25 | | - |
26 | | -PrintableTypes = [ |
27 | | - 'Bool', |
28 | | - 'Float32', |
29 | | - 'Float64' |
30 | | - ] |
31 | | - |
32 | | -for int_ty in all_integer_types(word_bits): |
33 | | - PrintableTypes.append(int_ty.stdlib_name) |
34 | | - |
35 | | -}% |
36 | | - |
37 | 13 | extension String : _ExpressibleByStringInterpolation { |
38 | 14 | /// Creates a new string by concatenating the given interpolations. |
39 | 15 | /// |
@@ -68,31 +44,33 @@ extension String : _ExpressibleByStringInterpolation { |
68 | 44 | self = String(describing: expr) |
69 | 45 | } |
70 | 46 |
|
71 | | -% for Type in StreamableTypes: |
72 | 47 | /// Creates a string containing the given value's textual representation. |
73 | 48 | /// |
74 | 49 | /// Do not call this initializer directly. It is used by the compiler when |
75 | 50 | /// interpreting string interpolations. |
76 | 51 | /// |
77 | 52 | /// - SeeAlso: `ExpressibleByStringInterpolation` |
78 | | - public init(stringInterpolationSegment expr: ${Type}) { |
| 53 | + public init<T: TextOutputStreamable> (stringInterpolationSegment expr: T) { |
79 | 54 | self = _toStringReadOnlyStreamable(expr) |
80 | 55 | } |
81 | | -% end |
82 | 56 |
|
83 | | -% for Type in PrintableTypes: |
84 | 57 | /// Creates a string containing the given value's textual representation. |
85 | 58 | /// |
86 | 59 | /// Do not call this initializer directly. It is used by the compiler when |
87 | 60 | /// interpreting string interpolations. |
88 | 61 | /// |
89 | 62 | /// - SeeAlso: `ExpressibleByStringInterpolation` |
90 | | - public init(stringInterpolationSegment expr: ${Type}) { |
| 63 | + public init<T: CustomStringConvertible> (stringInterpolationSegment expr: T) { |
91 | 64 | self = _toStringReadOnlyPrintable(expr) |
92 | 65 | } |
93 | | -% end |
94 | | -} |
95 | 66 |
|
96 | | -// ${'Local Variables'}: |
97 | | -// eval: (read-only-mode 1) |
98 | | -// End: |
| 67 | + /// Creates a string containing the given value's textual representation. |
| 68 | + /// |
| 69 | + /// Do not call this initializer directly. It is used by the compiler when |
| 70 | + /// interpreting string interpolations. |
| 71 | + /// |
| 72 | + /// - SeeAlso: `ExpressibleByStringInterpolation` |
| 73 | + public init<T: TextOutputStreamable & CustomStringConvertible> (stringInterpolationSegment expr: T) { |
| 74 | + self = _toStringReadOnlyStreamable(expr) |
| 75 | + } |
| 76 | +} |
0 commit comments