Skip to content

Commit c6883cb

Browse files
author
Dave Abrahams
committed
[stdlib] UnicodeDecoders: add _UTFEncoding and sink _isScalar there
1 parent 2ace06e commit c6883cb

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

test/Prototypes/UnicodeDecoders.swift

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,6 @@ public protocol _UnicodeEncodingBase {
265265
/// The replacement character U+FFFD as represented in this encoding
266266
static var encodedReplacementCharacter : EncodedScalar { get }
267267

268-
/// Returns true if `x` only appears in this encoding as the representation of
269-
/// a complete scalar value.
270-
static func _isScalar(_ x: CodeUnit) -> Bool
271-
272268
/// Convert from encoded to encoding-independent representation
273269
static func decode(_ content: Self.EncodedScalar) -> UnicodeScalar
274270
}
@@ -293,7 +289,7 @@ public protocol _UnicodeEncoding : _UnicodeEncodingBase {
293289
// where ReverseDecoder.Encoding == Self
294290
}
295291

296-
protocol UnicodeEncoding : _UnicodeEncoding
292+
public protocol UnicodeEncoding : _UnicodeEncoding
297293
where ForwardDecoder.Encoding == Self, ReverseDecoder.Encoding == Self {}
298294

299295
extension UnicodeDecoder {
@@ -361,8 +357,7 @@ extension Unicode {
361357
extension Unicode.DefaultScalarView : Sequence {
362358
struct Iterator {
363359
var parsing: Unicode.ParsingIterator<
364-
CodeUnits.Iterator, Encoding.ForwardDecoder
365-
>
360+
CodeUnits.Iterator, Encoding.ForwardDecoder>
366361
}
367362

368363
func makeIterator() -> Iterator {
@@ -515,11 +510,18 @@ extension Unicode.DefaultScalarView : BidirectionalCollection {
515510
}
516511
}
517512

513+
public protocol _UTFEncoding : UnicodeEncoding {
514+
/// Returns true if `x` only appears in this encoding as the representation of
515+
/// a complete scalar value.
516+
static func _isScalar(_ x: CodeUnit) -> Bool
517+
}
518+
518519
public protocol _UTFDecoder : UnicodeDecoder
519-
where Encoding.EncodedScalar == _UIntBuffer<_UInt32, Encoding.CodeUnit>,
520-
_UInt32 == UInt32
521-
{
520+
where Encoding : _UTFEncoding,
521+
Encoding.EncodedScalar == _UIntBuffer<_UInt32, Encoding.CodeUnit>,
522+
_UInt32 == UInt32 {
522523
associatedtype _UInt32 = UInt32
524+
523525
func _parseMultipleCodeUnits() -> (isValid: Bool, bitCount: UInt8)
524526
var buffer: Encoding.EncodedScalar { get set }
525527
func _bufferedScalar(bitCount: UInt8) -> Encoding.EncodedScalar
@@ -589,14 +591,16 @@ where Encoding.EncodedScalar == _UIntBuffer<UInt32, Encoding.CodeUnit> {
589591
//===--- UTF8 Decoders ----------------------------------------------------===//
590592
//===----------------------------------------------------------------------===//
591593

592-
extension Unicode.UTF8 : UnicodeEncoding {
594+
extension Unicode.UTF8 : _UTFEncoding {
593595
public typealias EncodedScalar = _UIntBuffer<UInt32, UInt8>
594596

595597
public static var encodedReplacementCharacter : EncodedScalar {
596598
return EncodedScalar(_storage: 0xbdbfef, _bitCount: 24)
597599
}
598600

599-
public static func _isScalar(_ x: CodeUnit) -> Bool { return x & 0x80 == 0 }
601+
public static func _isScalar(_ x: CodeUnit) -> Bool {
602+
return x & 0x80 == 0
603+
}
600604

601605
public static func decode(_ source: EncodedScalar) -> UnicodeScalar {
602606
let bits = source._storage
@@ -780,7 +784,7 @@ extension Unicode.UTF8.ForwardDecoder : _UTFDecoder {
780784
//===--- UTF-16 Decoders --------------------------------------------------===//
781785
//===----------------------------------------------------------------------===//
782786

783-
extension Unicode.UTF16 : UnicodeEncoding {
787+
extension Unicode.UTF16 : _UTFEncoding {
784788
public typealias EncodedScalar = _UIntBuffer<UInt32, UInt16>
785789

786790
public static var encodedReplacementCharacter : EncodedScalar {

0 commit comments

Comments
 (0)