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 {
185
185
}
186
186
187
187
fn read_line ( & self ) -> ~str {
188
- let mut line = ~"" ;
188
+ let mut bytes = ~[ ] ;
189
189
loop {
190
190
let ch = self . read_byte ( ) ;
191
191
if ch == -1 || ch == 10 { break ; }
192
- str :: push_char ( & mut line , ch as char ) ;
192
+ bytes . push ( ch as u8 ) ;
193
193
}
194
- line
194
+ str :: from_bytes ( bytes )
195
195
}
196
196
197
197
fn read_chars ( & self , n : uint ) -> ~[ char ] {
@@ -1221,6 +1221,14 @@ mod tests {
1221
1221
}
1222
1222
}
1223
1223
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
+
1224
1232
#[ test]
1225
1233
fn test_readchars_wide ( ) {
1226
1234
let wide_test = ~"生锈的汤匙切肉汤hello生锈的汤匙切肉汤";
You can’t perform that action at this time.
0 commit comments