@@ -278,9 +278,10 @@ public protocol UnicodeDecoder {
278
278
279
279
init ( )
280
280
281
- mutating func parseOne< I : IteratorProtocol > (
282
- _ input: inout I
283
- ) -> Unicode . ParseResult < Encoding . EncodedScalar > where I. Element == Encoding . CodeUnit
281
+ mutating func parseScalar< I : IteratorProtocol > (
282
+ from input: inout I
283
+ ) -> Unicode . ParseResult < Encoding . EncodedScalar >
284
+ where I. Element == Encoding . CodeUnit
284
285
}
285
286
286
287
public protocol _UnicodeEncoding : _UnicodeEncodingBase {
@@ -305,18 +306,18 @@ extension UnicodeDecoder {
305
306
) -> Int
306
307
where I. Element == Encoding . CodeUnit
307
308
{
308
- var errors = 0
309
+ var errorCount = 0
309
310
var d = Self ( )
310
311
while true {
311
- switch d. parseOne ( & input) {
312
+ switch d. parseScalar ( from : & input) {
312
313
case let . valid( scalarContent) :
313
314
output ( Encoding . decode ( scalarContent) )
314
315
case . invalid:
315
316
if !makeRepairs { return 1 }
316
- errors += 1
317
+ errorCount += 1
317
318
output ( UnicodeScalar ( _unchecked: 0xFFFD ) )
318
319
case . emptyInput:
319
- return errors
320
+ return errorCount
320
321
}
321
322
}
322
323
}
@@ -325,16 +326,17 @@ extension UnicodeDecoder {
325
326
326
327
extension Unicode {
327
328
struct ParsingIterator <
328
- CodeUnits : IteratorProtocol ,
329
+ CodeUnitIterator : IteratorProtocol ,
329
330
Decoder: UnicodeDecoder
330
- > where Decoder. Encoding. CodeUnit == CodeUnits . Element {
331
- var codeUnits : CodeUnits
331
+ > where Decoder. Encoding. CodeUnit == CodeUnitIterator . Element {
332
+ var codeUnits : CodeUnitIterator
332
333
var decoder : Decoder
333
334
}
334
335
}
336
+
335
337
extension Unicode . ParsingIterator : IteratorProtocol , Sequence {
336
338
mutating func next( ) -> Decoder . Encoding . EncodedScalar ? {
337
- switch decoder. parseOne ( & codeUnits) {
339
+ switch decoder. parseScalar ( from : & codeUnits) {
338
340
case let . valid( scalarContent) : return scalarContent
339
341
case . invalid: return Decoder . Encoding. encodedReplacementCharacter
340
342
case . emptyInput: return nil
@@ -439,7 +441,7 @@ extension Unicode.DefaultScalarView : Collection {
439
441
_elements: codeUnits, _position: nextPosition
440
442
)
441
443
var d = Encoding . ForwardDecoder ( )
442
- switch d. parseOne ( & i) {
444
+ switch d. parseScalar ( from : & i) {
443
445
case . valid( let scalarContent) :
444
446
return Index (
445
447
codeUnitIndex: nextPosition,
@@ -490,12 +492,12 @@ public struct ReverseIndexingIterator<
490
492
extension Unicode . DefaultScalarView : BidirectionalCollection {
491
493
@inline ( __always)
492
494
public func index( before i: Index ) -> Index {
493
- var d = Encoding . ReverseDecoder ( )
495
+ var decoder = Encoding . ReverseDecoder ( )
494
496
495
497
var more = ReverseIndexingIterator (
496
498
_elements: codeUnits, _position: i. codeUnitIndex)
497
499
498
- switch d . parseOne ( & more) {
500
+ switch decoder . parseScalar ( from : & more) {
499
501
case . valid( let scalarContent) :
500
502
let d : CodeUnits . IndexDistance = - numericCast( scalarContent. count)
501
503
return Index (
@@ -525,8 +527,8 @@ where Encoding.EncodedScalar == _UIntBuffer<_UInt32, Encoding.CodeUnit>,
525
527
}
526
528
527
529
extension _UTFDecoder where Encoding. EncodedScalar == _UIntBuffer < UInt32 , Encoding . CodeUnit > {
528
- public mutating func parseOne < I : IteratorProtocol > (
529
- _ input: inout I
530
+ public mutating func parseScalar < I : IteratorProtocol > (
531
+ from input: inout I
530
532
) -> Unicode . ParseResult < Encoding . EncodedScalar >
531
533
where I. Element == Encoding . CodeUnit {
532
534
@@ -548,15 +550,15 @@ extension _UTFDecoder where Encoding.EncodedScalar == _UIntBuffer<UInt32, Encodi
548
550
}
549
551
// Buffering mode.
550
552
// Fill buffer back to 4 bytes (or as many as are left in the iterator).
551
- _sanityCheck ( buffer. _bitCount < 32 )
553
+ _sanityCheck ( buffer. _bitCount < _UInt32 . bitWidth )
552
554
repeat {
553
555
if let codeUnit = input. next ( ) {
554
556
buffer. append ( codeUnit)
555
557
} else {
556
558
if buffer. isEmpty { return . emptyInput }
557
559
break // We still have some bytes left in our buffer.
558
560
}
559
- } while buffer. _bitCount < 32
561
+ } while buffer. _bitCount < _UInt32 . bitWidth
560
562
561
563
// Find one unicode scalar.
562
564
let ( isValid, scalarBitCount) = _parseMultipleCodeUnits ( )
0 commit comments