@@ -58,6 +58,7 @@ pub use self::decode::{decode_utf8, DecodeUtf8, InvalidSequence};
58
58
59
59
use fmt:: { self , Write } ;
60
60
use iter:: FusedIterator ;
61
+ use unicode:: mapping_table:: Lookup ;
61
62
62
63
// UTF-8 ranges and tags for encoding characters
63
64
const TAG_CONT : u8 = 0b1000_0000 ;
@@ -396,19 +397,33 @@ impl fmt::Display for EscapeDebug {
396
397
/// [`char`]: ../../std/primitive.char.html
397
398
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
398
399
#[ derive( Debug , Clone ) ]
399
- pub struct ToLowercase ( CaseMappingIter ) ;
400
+ pub struct ToLowercase ( Lookup ) ;
400
401
401
402
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
402
403
impl Iterator for ToLowercase {
403
404
type Item = char ;
405
+
406
+ #[ inline]
404
407
fn next ( & mut self ) -> Option < char > {
405
408
self . 0 . next ( )
406
409
}
410
+
411
+ #[ inline]
412
+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
413
+ self . 0 . size_hint ( )
414
+ }
407
415
}
408
416
409
417
#[ stable( feature = "fused" , since = "1.26.0" ) ]
410
418
impl FusedIterator for ToLowercase { }
411
419
420
+ #[ stable( feature = "char_struct_display" , since = "1.16.0" ) ]
421
+ impl fmt:: Display for ToLowercase {
422
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
423
+ fmt:: Display :: fmt ( & self . 0 , f)
424
+ }
425
+ }
426
+
412
427
/// Returns an iterator that yields the uppercase equivalent of a `char`.
413
428
///
414
429
/// This `struct` is created by the [`to_uppercase`] method on [`char`]. See
@@ -418,88 +433,25 @@ impl FusedIterator for ToLowercase {}
418
433
/// [`char`]: ../../std/primitive.char.html
419
434
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
420
435
#[ derive( Debug , Clone ) ]
421
- pub struct ToUppercase ( CaseMappingIter ) ;
436
+ pub struct ToUppercase ( Lookup ) ;
422
437
423
438
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
424
439
impl Iterator for ToUppercase {
425
440
type Item = char ;
426
- fn next ( & mut self ) -> Option < char > {
427
- self . 0 . next ( )
428
- }
429
- }
430
-
431
- #[ stable( feature = "fused" , since = "1.26.0" ) ]
432
- impl FusedIterator for ToUppercase { }
433
-
434
- #[ derive( Debug , Clone ) ]
435
- enum CaseMappingIter {
436
- Three ( char , char , char ) ,
437
- Two ( char , char ) ,
438
- One ( char ) ,
439
- Zero ,
440
- }
441
-
442
- impl CaseMappingIter {
443
- fn new ( chars : [ char ; 3 ] ) -> CaseMappingIter {
444
- if chars[ 2 ] == '\0' {
445
- if chars[ 1 ] == '\0' {
446
- CaseMappingIter :: One ( chars[ 0 ] ) // Including if chars[0] == '\0'
447
- } else {
448
- CaseMappingIter :: Two ( chars[ 0 ] , chars[ 1 ] )
449
- }
450
- } else {
451
- CaseMappingIter :: Three ( chars[ 0 ] , chars[ 1 ] , chars[ 2 ] )
452
- }
453
- }
454
- }
455
441
456
- impl Iterator for CaseMappingIter {
457
- type Item = char ;
442
+ #[ inline]
458
443
fn next ( & mut self ) -> Option < char > {
459
- match * self {
460
- CaseMappingIter :: Three ( a, b, c) => {
461
- * self = CaseMappingIter :: Two ( b, c) ;
462
- Some ( a)
463
- }
464
- CaseMappingIter :: Two ( b, c) => {
465
- * self = CaseMappingIter :: One ( c) ;
466
- Some ( b)
467
- }
468
- CaseMappingIter :: One ( c) => {
469
- * self = CaseMappingIter :: Zero ;
470
- Some ( c)
471
- }
472
- CaseMappingIter :: Zero => None ,
473
- }
444
+ self . 0 . next ( )
474
445
}
475
- }
476
446
477
- impl fmt:: Display for CaseMappingIter {
478
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
479
- match * self {
480
- CaseMappingIter :: Three ( a, b, c) => {
481
- f. write_char ( a) ?;
482
- f. write_char ( b) ?;
483
- f. write_char ( c)
484
- }
485
- CaseMappingIter :: Two ( b, c) => {
486
- f. write_char ( b) ?;
487
- f. write_char ( c)
488
- }
489
- CaseMappingIter :: One ( c) => {
490
- f. write_char ( c)
491
- }
492
- CaseMappingIter :: Zero => Ok ( ( ) ) ,
493
- }
447
+ #[ inline]
448
+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
449
+ self . 0 . size_hint ( )
494
450
}
495
451
}
496
452
497
- #[ stable( feature = "char_struct_display" , since = "1.16.0" ) ]
498
- impl fmt:: Display for ToLowercase {
499
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
500
- fmt:: Display :: fmt ( & self . 0 , f)
501
- }
502
- }
453
+ #[ stable( feature = "fused" , since = "1.26.0" ) ]
454
+ impl FusedIterator for ToUppercase { }
503
455
504
456
#[ stable( feature = "char_struct_display" , since = "1.16.0" ) ]
505
457
impl fmt:: Display for ToUppercase {
0 commit comments