File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -919,6 +919,14 @@ fn test_char_indices_revator() {
919919 assert_eq ! ( pos, p. len( ) ) ;
920920}
921921
922+ #[ test]
923+ fn test_char_indices_last ( ) {
924+ let s = "ศไทย中华Việt Nam" ;
925+ let mut it = s. char_indices ( ) ;
926+ it. next ( ) ;
927+ assert_eq ! ( it. last( ) , Some ( ( 27 , 'm' ) ) ) ;
928+ }
929+
922930#[ test]
923931fn test_splitn_char_iterator ( ) {
924932 let data = "\n Märy häd ä little lämb\n Little lämb\n " ;
Original file line number Diff line number Diff line change @@ -511,6 +511,12 @@ impl<'a> Iterator for CharIndices<'a> {
511511 fn size_hint ( & self ) -> ( usize , Option < usize > ) {
512512 self . iter . size_hint ( )
513513 }
514+
515+ #[ inline]
516+ fn last ( mut self ) -> Option < ( usize , char ) > {
517+ // No need to go through the entire string.
518+ self . next_back ( )
519+ }
514520}
515521
516522#[ stable( feature = "rust1" , since = "1.0.0" ) ]
You can’t perform that action at this time.
0 commit comments