File tree 2 files changed +14
-0
lines changed
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() {
919
919
assert_eq ! ( pos, p. len( ) ) ;
920
920
}
921
921
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
+
922
930
#[ test]
923
931
fn test_splitn_char_iterator ( ) {
924
932
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> {
511
511
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
512
512
self . iter . size_hint ( )
513
513
}
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
+ }
514
520
}
515
521
516
522
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
You can’t perform that action at this time.
0 commit comments