File tree 1 file changed +17
-0
lines changed
1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -466,6 +466,23 @@ impl Iterator for EscapeUnicode {
466
466
self . len ( )
467
467
}
468
468
469
+ fn nth ( & mut self , n : usize ) -> Option < char > {
470
+ let remaining = self . len ( ) . saturating_sub ( n) ;
471
+
472
+ // offset = (number of hex digits still to be emitted) - 1
473
+ // It can be computed from the remaining number of items by keeping
474
+ // into account that:
475
+ // - offset can never increase
476
+ // - the last 2 items (last hex digit, '}') are not counted in offset
477
+ let offset = :: cmp:: min ( self . offset , remaining. saturating_sub ( 2 ) ) ;
478
+
479
+ // state = number of items to be emitted for the state (as per state_len())
480
+ // It can be computed because (remaining number of items) = state + offset
481
+ let state = remaining - offset;
482
+
483
+ self . step ( state, offset)
484
+ }
485
+
469
486
fn last ( self ) -> Option < char > {
470
487
match self . state {
471
488
EscapeUnicodeState :: Done => None ,
You can’t perform that action at this time.
0 commit comments