File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -185,13 +185,13 @@ impl<T: Reader> T : ReaderUtil {
185185 }
186186
187187 fn read_line ( & self ) -> ~str {
188- let mut line = ~"" ;
188+ let mut bytes = ~[ ] ;
189189 loop {
190190 let ch = self . read_byte ( ) ;
191191 if ch == -1 || ch == 10 { break ; }
192- str :: push_char ( & mut line , ch as char ) ;
192+ bytes . push ( ch as u8 ) ;
193193 }
194- line
194+ str :: from_bytes ( bytes )
195195 }
196196
197197 fn read_chars ( & self , n : uint ) -> ~[ char ] {
@@ -1221,6 +1221,14 @@ mod tests {
12211221 }
12221222 }
12231223
1224+ #[ test]
1225+ fn test_read_line_utf8 ( ) {
1226+ do io:: with_str_reader ( ~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤") |inp| {
1227+ let line = inp. read_line ( ) ;
1228+ assert line == ~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤";
1229+ }
1230+ }
1231+
12241232 #[ test]
12251233 fn test_readchars_wide ( ) {
12261234 let wide_test = ~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤";
You can’t perform that action at this time.
0 commit comments