File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -203,11 +203,9 @@ impl NBReader {
203203 pub fn try_read ( & mut self ) -> Option < char > {
204204 // discard eventual errors, EOF will be handled in read_until correctly
205205 let _ = self . read_into_buffer ( ) ;
206- if !self . buffer . is_empty ( ) {
207- self . buffer . drain ( ..1 ) . last ( )
208- } else {
209- None
210- }
206+ let first = self . buffer . chars ( ) . next ( ) ?;
207+ self . buffer . drain ( ..first. len_utf8 ( ) ) ;
208+ Some ( first)
211209 }
212210}
213211
@@ -459,13 +457,17 @@ mod tests {
459457 }
460458
461459 #[ test]
462- #[ should_panic = "is_char_boundary" ]
463460 fn test_try_read_multibyte ( ) {
464461 let f = io:: Cursor :: new ( "\u{c3} " ) ;
465462 let mut r = NBReader :: new ( f, Options :: default ( ) ) ;
463+ let mut chars = String :: new ( ) ;
466464 let deadline = time:: Instant :: now ( ) + time:: Duration :: from_secs ( 5 ) ;
467- while time:: Instant :: now ( ) < deadline {
468- let _ = r. try_read ( ) ;
465+ while chars. chars ( ) . count ( ) < 2 && time:: Instant :: now ( ) < deadline {
466+ if let Some ( c) = r. try_read ( ) {
467+ chars. push ( c) ;
468+ }
469469 }
470+ assert_eq ! ( chars, "\u{c3} \u{83} " ) ;
471+ assert_eq ! ( None , r. try_read( ) ) ;
470472 }
471473}
You can’t perform that action at this time.
0 commit comments