@@ -58,6 +58,7 @@ pub use self::decode::{decode_utf8, DecodeUtf8, InvalidSequence};
5858
5959use fmt:: { self , Write } ;
6060use iter:: FusedIterator ;
61+ use unicode:: mapping_table:: Lookup ;
6162
6263// UTF-8 ranges and tags for encoding characters
6364const TAG_CONT : u8 = 0b1000_0000 ;
@@ -396,19 +397,33 @@ impl fmt::Display for EscapeDebug {
396397/// [`char`]: ../../std/primitive.char.html
397398#[ stable( feature = "rust1" , since = "1.0.0" ) ]
398399#[ derive( Debug , Clone ) ]
399- pub struct ToLowercase ( CaseMappingIter ) ;
400+ pub struct ToLowercase ( Lookup ) ;
400401
401402#[ stable( feature = "rust1" , since = "1.0.0" ) ]
402403impl Iterator for ToLowercase {
403404 type Item = char ;
405+
406+ #[ inline]
404407 fn next ( & mut self ) -> Option < char > {
405408 self . 0 . next ( )
406409 }
410+
411+ #[ inline]
412+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
413+ self . 0 . size_hint ( )
414+ }
407415}
408416
409417#[ stable( feature = "fused" , since = "1.26.0" ) ]
410418impl FusedIterator for ToLowercase { }
411419
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+
412427/// Returns an iterator that yields the uppercase equivalent of a `char`.
413428///
414429/// This `struct` is created by the [`to_uppercase`] method on [`char`]. See
@@ -418,88 +433,25 @@ impl FusedIterator for ToLowercase {}
418433/// [`char`]: ../../std/primitive.char.html
419434#[ stable( feature = "rust1" , since = "1.0.0" ) ]
420435#[ derive( Debug , Clone ) ]
421- pub struct ToUppercase ( CaseMappingIter ) ;
436+ pub struct ToUppercase ( Lookup ) ;
422437
423438#[ stable( feature = "rust1" , since = "1.0.0" ) ]
424439impl Iterator for ToUppercase {
425440 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- }
455441
456- impl Iterator for CaseMappingIter {
457- type Item = char ;
442+ #[ inline]
458443 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 ( )
474445 }
475- }
476446
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 ( )
494450 }
495451}
496452
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 { }
503455
504456#[ stable( feature = "char_struct_display" , since = "1.16.0" ) ]
505457impl fmt:: Display for ToUppercase {
0 commit comments