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 @@ -446,6 +446,23 @@ impl Iterator for EscapeUnicode {
446
446
self . len ( )
447
447
}
448
448
449
+ fn nth ( & mut self , n : usize ) -> Option < char > {
450
+ let remaining = self . len ( ) . saturating_sub ( n) ;
451
+
452
+ // hex_digit_idx = (number of hex digits still to be emitted) - 1
453
+ // It can be computed from the remaining number of items by keeping
454
+ // into account that:
455
+ // - hex_digit_idx can never increase
456
+ // - the last 2 items (last hex digit, '}') are not counted in hex_digit_idx
457
+ let hex_digit_idx = :: cmp:: min ( self . hex_digit_idx , remaining. saturating_sub ( 2 ) ) ;
458
+
459
+ // state = number of items to be emitted for the state (as per state_len())
460
+ // It can be computed because (remaining number of items) = state + hex_digit_idx
461
+ let state = remaining - hex_digit_idx;
462
+
463
+ self . step ( state, hex_digit_idx)
464
+ }
465
+
449
466
fn last ( self ) -> Option < char > {
450
467
match self . state {
451
468
EscapeUnicodeState :: Done => None ,
You can’t perform that action at this time.
0 commit comments