@@ -364,6 +364,15 @@ extension UInt8 {
364
364
" Code point value does not fit into ASCII " )
365
365
self = UInt8 ( v. value)
366
366
}
367
+ /// Initializes a UInt8 with the ASCII value of the provided Unicode scalar if possible.
368
+ ///
369
+ /// - Parameter unicode: The Unicode scalar to initialize from.
370
+ /// - Note: Construct with value `v.value`.
371
+ @inlinable @_alwaysEmitIntoClient
372
+ public init ? ( ifASCII v: Unicode . Scalar ) {
373
+ guard v. value < 128 else { return nil }
374
+ self = Self ( v. value)
375
+ }
367
376
}
368
377
extension UInt32 {
369
378
/// Construct with value `v.value`.
@@ -380,51 +389,6 @@ extension UInt64 {
380
389
}
381
390
}
382
391
383
- /// Extends `UInt8` providing initialization from a Unicode scalar.
384
- extension UInt8 {
385
- /// Converts a UInt8 ASCII value into a UnicodeScalar
386
- @_transparent @_alwaysEmitIntoClient
387
- var asciiScalar : Unicode . Scalar ? {
388
- guard self < 0x80 else { return nil }
389
- return Unicode . Scalar ( self )
390
- }
391
- /// Initializes a FixedWidthInteger with the value of the provided Unicode scalar.
392
- ///
393
- /// - Parameter unicode: The Unicode scalar to initialize from.
394
- /// - Note: Construct with value `v.value`.
395
- @inlinable @_alwaysEmitIntoClient
396
- public init ? ( ifASCII v: Unicode . Scalar ) {
397
- guard v. value < 0x80 else { return nil }
398
- self = Self ( v. value)
399
- }
400
- }
401
-
402
- /// Extends `UInt8` to allow direct comparisons with double quoted literals.
403
- extension UInt8 {
404
- /// Returns a Boolean indicating whether the `UInt8` is equal to the provided Unicode scalar.
405
- ///
406
- /// - Parameters:
407
- /// - i: The `UInt8` value to compare.
408
- /// - s: The Unicode scalar to compare against.
409
- /// - Returns: `true` when the `UInt8` is equal to the provided Unicode scalar; otherwise, `false`.
410
- @_transparent @_alwaysEmitIntoClient
411
- public static func == ( i: Self , s: Unicode . Scalar ) -> Bool {
412
- return i == UInt8 ( ifASCII: s)
413
- }
414
-
415
- /// Returns a Boolean indicating whether the `UInt8` is not equal to the provided Unicode scalar.
416
- @_transparent @_alwaysEmitIntoClient
417
- public static func != ( i: Self , s: Unicode . Scalar ) -> Bool {
418
- return i != UInt8 ( ifASCII: s)
419
- }
420
-
421
- /// Enables pattern matching of Unicode scalars in switch statements.
422
- @_transparent @_alwaysEmitIntoClient
423
- public static func ~= ( s: Unicode . Scalar , i: Self ) -> Bool {
424
- return i == UInt8 ( ifASCII: s)
425
- }
426
- }
427
-
428
392
/// Extends `Optional<UInt8>` to allow direct comparisons with double quoted literals.
429
393
extension UInt8 ? {
430
394
/// Returns a Boolean value indicating whether the optional `UInt8` is equal to the provided Unicode scalar.
@@ -462,6 +426,12 @@ extension FixedWidthInteger {
462
426
guard v. value <= Self . max else { return nil }
463
427
self = Self ( v. value)
464
428
}
429
+ /// Converts an ASCII value into a UnicodeScalar
430
+ @inlinable @_alwaysEmitIntoClient
431
+ public var asciiScalar : Unicode . Scalar ? {
432
+ guard self < 128 && self >= 0 else { return nil }
433
+ return Unicode . Scalar ( UInt8 ( self ) )
434
+ }
465
435
}
466
436
467
437
extension Unicode . Scalar : Equatable {
0 commit comments