9
9
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10
10
//
11
11
//===----------------------------------------------------------------------===//
12
-
12
+ //
13
13
// Implementation Note: Because StaticString is used in the
14
14
// implementation of _precondition(), _fatalErrorMessage(), etc., we
15
15
// keep it extremely close to the bare metal. In particular, because
16
16
// we store only Builtin types, we are guaranteed that no assertions
17
17
// are involved in its construction. This feature is crucial for
18
18
// preventing infinite recursion even in non-asserting cases.
19
+ //
20
+ //===----------------------------------------------------------------------===//
19
21
20
22
/// A string type designed to represent text that is known at compile time.
21
23
///
67
69
/// utf8[4] //-> Fatal error!
68
70
/// }
69
71
@frozen
70
- public struct StaticString
71
- : _ExpressibleByBuiltinUnicodeScalarLiteral ,
72
- _ExpressibleByBuiltinExtendedGraphemeClusterLiteral ,
73
- _ExpressibleByBuiltinStringLiteral ,
74
- ExpressibleByUnicodeScalarLiteral ,
75
- ExpressibleByExtendedGraphemeClusterLiteral ,
76
- ExpressibleByStringLiteral ,
77
- CustomStringConvertible ,
78
- CustomDebugStringConvertible ,
79
- CustomReflectable {
72
+ public struct StaticString {
80
73
81
74
/// Either a pointer to the start of UTF-8 data, represented as an integer,
82
75
/// or an integer representation of a single Unicode scalar.
@@ -228,12 +221,18 @@ public struct StaticString
228
221
? ( 0x3 as UInt8 ) . _value
229
222
: ( 0x1 as UInt8 ) . _value
230
223
}
224
+ }
225
+
226
+ extension StaticString : _ExpressibleByBuiltinUnicodeScalarLiteral {
231
227
232
228
@_effects ( readonly)
233
229
@_transparent
234
230
public init ( _builtinUnicodeScalarLiteral value: Builtin . Int32 ) {
235
231
self = StaticString ( unicodeScalar: value)
236
232
}
233
+ }
234
+
235
+ extension StaticString : ExpressibleByUnicodeScalarLiteral {
237
236
238
237
/// Creates an instance initialized to a single Unicode scalar.
239
238
///
@@ -244,6 +243,9 @@ public struct StaticString
244
243
public init ( unicodeScalarLiteral value: StaticString ) {
245
244
self = value
246
245
}
246
+ }
247
+
248
+ extension StaticString : _ExpressibleByBuiltinExtendedGraphemeClusterLiteral {
247
249
248
250
@_effects ( readonly)
249
251
@_transparent
@@ -258,6 +260,9 @@ public struct StaticString
258
260
isASCII: isASCII
259
261
)
260
262
}
263
+ }
264
+
265
+ extension StaticString : ExpressibleByExtendedGraphemeClusterLiteral {
261
266
262
267
/// Creates an instance initialized to a single character that is made up of
263
268
/// one or more Unicode scalar values.
@@ -269,6 +274,9 @@ public struct StaticString
269
274
public init ( extendedGraphemeClusterLiteral value: StaticString ) {
270
275
self = value
271
276
}
277
+ }
278
+
279
+ extension StaticString : _ExpressibleByBuiltinStringLiteral {
272
280
273
281
@_effects ( readonly)
274
282
@_transparent
@@ -282,6 +290,9 @@ public struct StaticString
282
290
utf8CodeUnitCount: utf8CodeUnitCount,
283
291
isASCII: isASCII)
284
292
}
293
+ }
294
+
295
+ extension StaticString : ExpressibleByStringLiteral {
285
296
286
297
/// Creates an instance initialized to the value of a string literal.
287
298
///
@@ -292,19 +303,26 @@ public struct StaticString
292
303
public init ( stringLiteral value: StaticString ) {
293
304
self = value
294
305
}
306
+ }
307
+
308
+ extension StaticString : CustomStringConvertible {
295
309
296
310
/// A textual representation of the static string.
297
311
public var description : String {
298
312
return withUTF8Buffer { String . _uncheckedFromUTF8 ( $0) }
299
313
}
314
+ }
315
+
316
+ extension StaticString : CustomDebugStringConvertible {
300
317
301
318
/// A textual representation of the static string, suitable for debugging.
302
319
public var debugDescription : String {
303
320
return self . description. debugDescription
304
321
}
305
322
}
306
323
307
- extension StaticString {
324
+ extension StaticString : CustomReflectable {
325
+
308
326
public var customMirror : Mirror {
309
327
return Mirror ( reflecting: description)
310
328
}
0 commit comments