@@ -185,9 +185,7 @@ impl CharExt for char {
185185 '\t' => EscapeDefaultState :: Backslash ( 't' ) ,
186186 '\r' => EscapeDefaultState :: Backslash ( 'r' ) ,
187187 '\n' => EscapeDefaultState :: Backslash ( 'n' ) ,
188- '\\' => EscapeDefaultState :: Backslash ( '\\' ) ,
189- '\'' => EscapeDefaultState :: Backslash ( '\'' ) ,
190- '"' => EscapeDefaultState :: Backslash ( '"' ) ,
188+ '\\' | '\'' | '"' => EscapeDefaultState :: Backslash ( self ) ,
191189 '\x20' ... '\x7e' => EscapeDefaultState :: Char ( self ) ,
192190 _ => EscapeDefaultState :: Unicode ( self . escape_unicode ( ) )
193191 } ;
@@ -344,6 +342,22 @@ impl Iterator for EscapeUnicode {
344342 EscapeUnicodeState :: Done => None ,
345343 }
346344 }
345+
346+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
347+ let mut n = 0 ;
348+ while ( self . c as usize ) >> ( 4 * ( n + 1 ) ) != 0 {
349+ n += 1 ;
350+ }
351+ let n = match self . state {
352+ EscapeUnicodeState :: Backslash => n + 5 ,
353+ EscapeUnicodeState :: Type => n + 4 ,
354+ EscapeUnicodeState :: LeftBrace => n + 3 ,
355+ EscapeUnicodeState :: Value ( offset) => offset + 2 ,
356+ EscapeUnicodeState :: RightBrace => 1 ,
357+ EscapeUnicodeState :: Done => 0 ,
358+ } ;
359+ ( n, Some ( n) )
360+ }
347361}
348362
349363/// An iterator over the characters that represent a `char`, escaped
@@ -377,7 +391,16 @@ impl Iterator for EscapeDefault {
377391 Some ( c)
378392 }
379393 EscapeDefaultState :: Done => None ,
380- EscapeDefaultState :: Unicode ( ref mut iter) => iter. next ( )
394+ EscapeDefaultState :: Unicode ( ref mut iter) => iter. next ( ) ,
395+ }
396+ }
397+
398+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
399+ match self . state {
400+ EscapeDefaultState :: Char ( _) => ( 1 , Some ( 1 ) ) ,
401+ EscapeDefaultState :: Backslash ( _) => ( 2 , Some ( 2 ) ) ,
402+ EscapeDefaultState :: Unicode ( ref iter) => iter. size_hint ( ) ,
403+ EscapeDefaultState :: Done => ( 0 , Some ( 0 ) ) ,
381404 }
382405 }
383406}
0 commit comments