@@ -434,6 +434,51 @@ extension Unicode.Scalar.UTF16View : RandomAccessCollection {
434434 }
435435}
436436
437+ extension Unicode . Scalar {
438+ @available ( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , * )
439+ @_fixed_layout
440+ public struct UTF8View {
441+ @inlinable
442+ internal init ( value: Unicode . Scalar ) {
443+ self . value = value
444+ }
445+ @usableFromInline
446+ internal var value : Unicode . Scalar
447+ }
448+
449+ @available ( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , * )
450+ @inlinable
451+ public var utf8 : UTF8View { return UTF8View ( value: self ) }
452+ }
453+
454+ @available ( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , * )
455+ extension Unicode . Scalar . UTF8View : RandomAccessCollection {
456+ public typealias Indices = Range < Int >
457+
458+ /// The position of the first code unit.
459+ @inlinable
460+ public var startIndex : Int { return 0 }
461+
462+ /// The "past the end" position---that is, the position one
463+ /// greater than the last valid subscript argument.
464+ ///
465+ /// If the collection is empty, `endIndex` is equal to `startIndex`.
466+ @inlinable
467+ public var endIndex : Int { return 0 + UTF8. width ( value) }
468+
469+ /// Accesses the code unit at the specified position.
470+ ///
471+ /// - Parameter position: The position of the element to access. `position`
472+ /// must be a valid index of the collection that is not equal to the
473+ /// `endIndex` property.
474+ @inlinable
475+ public subscript( position: Int ) -> UTF8 . CodeUnit {
476+ _precondition ( position >= startIndex && position < endIndex,
477+ " Unicode.Scalar.UTF8View index is out of bounds " )
478+ return value. withUTF8CodeUnits { $0 [ position] }
479+ }
480+ }
481+
437482extension Unicode . Scalar {
438483 internal static var _replacementCharacter : Unicode . Scalar {
439484 return Unicode . Scalar ( _value: UTF32 . _replacementCodeUnit)
0 commit comments