@@ -380,53 +380,89 @@ extension UInt64 {
380
380
}
381
381
}
382
382
383
- extension FixedWidthInteger {
384
- /// Construct with value `v.value`.
385
- @inlinable @_alwaysEmitIntoClient
386
- public init ( unicode v: Unicode . Scalar ) {
387
- _precondition ( v. value <= Self . max,
388
- " Code point value does not fit into type " )
389
- self = Self ( v. value)
390
- }
391
- }
392
-
393
- /// Allows direct comparisons between UInt8 and double quoted literals.
383
+ /// Extends `UInt8` to allow direct comparisons with double quoted literals.
394
384
extension UInt8 {
395
- /// Basic equality operator
385
+ /// Returns a Boolean indicating whether the `UInt8` is equal to the provided Unicode scalar.
386
+ ///
387
+ /// - Parameters:
388
+ /// - i: The `UInt8` value to compare.
389
+ /// - s: The Unicode scalar to compare against.
390
+ /// - Returns: `true` when the `UInt8` is equal to the provided Unicode scalar; otherwise, `false`.
396
391
@_transparent @_alwaysEmitIntoClient
397
392
public static func == ( i: Self , s: Unicode . Scalar ) -> Bool {
398
393
return i == UInt8 ( ascii: s)
399
394
}
400
- /// Basic inequality operator
395
+
396
+ /// Returns a Boolean indicating whether the `UInt8` is not equal to the provided Unicode scalar.
401
397
@_transparent @_alwaysEmitIntoClient
402
398
public static func != ( i: Self , s: Unicode . Scalar ) -> Bool {
403
399
return i != UInt8 ( ascii: s)
404
400
}
405
- /// Used in switch statements
401
+
402
+ /// Enables pattern matching of Unicode scalars in switch statements.
406
403
@_transparent @_alwaysEmitIntoClient
407
404
public static func ~= ( s: Unicode . Scalar , i: Self ) -> Bool {
408
405
return i == UInt8 ( ascii: s)
409
406
}
410
407
}
411
408
409
+ /// Extends `Optional<UInt8>` to allow direct comparisons with double quoted literals.
412
410
extension UInt8 ? {
413
- /// Optional equality operator
411
+ /// Returns a Boolean value indicating whether the optional `UInt8` is equal to the provided Unicode scalar.
412
+ ///
413
+ /// - Parameters:
414
+ /// - i: The optional `UInt8` value to compare.
415
+ /// - s: The Unicode scalar to compare against.
416
+ /// - Returns: `true` if the optional `UInt8` is equal to the provided Unicode scalar; otherwise, `false`.
414
417
@_transparent @_alwaysEmitIntoClient
415
418
public static func == ( i: Self , s: Unicode . Scalar ) -> Bool {
416
419
return i == UInt8 ( ascii: s)
417
420
}
418
- /// Optional inequality operator
421
+
422
+ /// Returns a Boolean value indicating whether the optional `UInt8` is not equal to the provided Unicode scalar.
419
423
@_transparent @_alwaysEmitIntoClient
420
424
public static func != ( i: Self , s: Unicode . Scalar ) -> Bool {
421
425
return i != UInt8 ( ascii: s)
422
426
}
423
- /// Used in switch statements
427
+
428
+ /// Allows pattern matching of Unicode scalars in switch statements.
424
429
@_transparent @_alwaysEmitIntoClient
425
430
public static func ~= ( s: Unicode . Scalar , i: Self ) -> Bool {
426
431
return i == UInt8 ( ascii: s)
427
432
}
428
433
}
429
434
435
+ /// Extends `Array` where Element is a FixedWidthInteger, providing initialization from a string of Unicode scalars.
436
+ @_unavailableInEmbedded
437
+ extension Array where Element: FixedWidthInteger {
438
+ /// Initializes an array of Integers with Unicode scalars represented by the provided string.
439
+ ///
440
+ /// - Parameter scalars: A string containing Unicode scalars.
441
+ @inlinable @_alwaysEmitIntoClient @_unavailableInEmbedded
442
+ public init ( scalars: String ) {
443
+ #if os(Linux) || os(iOS) || os(tvOS)
444
+ // How to avoid the function body being type checked for embedded?
445
+ self . init ( scalars. unicodeScalars. map { Element ( unicode: $0) } )
446
+ #else
447
+ self . init ( scalars. utf16. map { Element ( $0) } )
448
+ #endif
449
+ }
450
+ }
451
+
452
+ /// Extends `FixedWidthInteger` providing initialization from a Unicode scalar.
453
+ extension FixedWidthInteger {
454
+ /// Initializes a FixedWidthInteger with the value of the provided Unicode scalar.
455
+ ///
456
+ /// - Parameter unicode: The Unicode scalar to initialize from.
457
+ /// - Note: Construct with value `v.value`.
458
+ @inlinable @_alwaysEmitIntoClient
459
+ public init ( unicode v: Unicode . Scalar ) {
460
+ _precondition ( v. value <= Self . max,
461
+ " Code point value does not fit into type " )
462
+ self = Self ( v. value)
463
+ }
464
+ }
465
+
430
466
extension Unicode . Scalar : Equatable {
431
467
@inlinable
432
468
public static func == ( lhs: Unicode . Scalar , rhs: Unicode . Scalar ) -> Bool {
0 commit comments