@@ -99,8 +99,8 @@ pub trait ReaderUtil {
99
99
/// Read len bytes into a new vec.
100
100
fn read_bytes ( & self , len : uint ) -> ~[ u8 ] ;
101
101
102
- /// Read up until a specified character (which is optionally included ) or EOF.
103
- fn read_until ( & self , c : char , include : bool ) -> ~str ;
102
+ /// Read up until a specified character (which is not returned ) or EOF.
103
+ fn read_until ( & self , c : char ) -> ~str ;
104
104
105
105
/// Read up until the first '\n' char (which is not returned), or EOF.
106
106
fn read_line ( & self ) -> ~str ;
@@ -126,9 +126,6 @@ pub trait ReaderUtil {
126
126
/// Iterate over every line until the iterator breaks or EOF.
127
127
fn each_line ( & self , it : & fn ( & str ) -> bool ) ;
128
128
129
- /// Read all the lines of the file into a vector.
130
- fn read_lines ( & self ) -> ~[ ~str ] ;
131
-
132
129
/// Read n (between 1 and 8) little-endian unsigned integer bytes.
133
130
fn read_le_uint_n ( & self , nbytes : uint ) -> u64 ;
134
131
@@ -222,14 +219,11 @@ impl<T:Reader> ReaderUtil for T {
222
219
bytes
223
220
}
224
221
225
- fn read_until ( & self , c : char , include : bool ) -> ~str {
222
+ fn read_until ( & self , c : char ) -> ~str {
226
223
let mut bytes = ~[ ] ;
227
224
loop {
228
225
let ch = self . read_byte ( ) ;
229
226
if ch == -1 || ch == c as int {
230
- if include && ch == c as int {
231
- bytes. push ( ch as u8 ) ;
232
- }
233
227
break ;
234
228
}
235
229
bytes. push ( ch as u8 ) ;
@@ -238,7 +232,7 @@ impl<T:Reader> ReaderUtil for T {
238
232
}
239
233
240
234
fn read_line ( & self ) -> ~str {
241
- self . read_until ( '\n' , false )
235
+ self . read_until ( '\n' )
242
236
}
243
237
244
238
fn read_chars ( & self , n : uint ) -> ~[ char ] {
@@ -312,7 +306,7 @@ impl<T:Reader> ReaderUtil for T {
312
306
}
313
307
314
308
fn read_c_str ( & self ) -> ~str {
315
- self . read_until ( 0 as char , false )
309
+ self . read_until ( 0 as char )
316
310
}
317
311
318
312
fn read_whole_stream ( & self ) -> ~[ u8 ] {
@@ -335,29 +329,7 @@ impl<T:Reader> ReaderUtil for T {
335
329
336
330
fn each_line ( & self , it : & fn ( s : & str ) -> bool ) {
337
331
while !self . eof ( ) {
338
- // include the \n, so that we can distinguish an entirely empty
339
- // line read after "...\n", and the trailing empty line in
340
- // "...\n\n".
341
- let mut line = self . read_until ( '\n' , true ) ;
342
-
343
- // blank line at the end of the reader is ignored
344
- if self . eof ( ) && line. is_empty ( ) { break ; }
345
-
346
- // trim the \n, so that each_line is consistent with read_line
347
- let n = str:: len ( line) ;
348
- if line[ n-1 ] == '\n' as u8 {
349
- unsafe { str:: raw:: set_len ( & mut line, n-1 ) ; }
350
- }
351
-
352
- if !it ( line) { break ; }
353
- }
354
- }
355
-
356
- fn read_lines ( & self ) -> ~[ ~str ] {
357
- do vec:: build |push| {
358
- for self . each_line |line| {
359
- push( str:: from_slice( line) ) ;
360
- }
332
+ if !it ( self . read_line ( ) ) { break ; }
361
333
}
362
334
}
363
335
@@ -1363,21 +1335,6 @@ mod tests {
1363
1335
}
1364
1336
}
1365
1337
1366
- #[test]
1367
- fn test_read_lines() {
1368
- do io::with_str_reader(~" a\n b\n c\n ") |inp| {
1369
- fail_unless!( inp. read_lines( ) == ~[ ~"a", ~" b", ~" c"]);
1370
- }
1371
-
1372
- do io::with_str_reader(~" a\n b\n c") |inp| {
1373
- fail_unless!(inp.read_lines() == ~[~" a", ~" b", ~" c"]);
1374
- }
1375
-
1376
- do io::with_str_reader(~" ") |inp| {
1377
- fail_unless!(inp.read_lines().is_empty());
1378
- }
1379
- }
1380
-
1381
1338
#[test]
1382
1339
fn test_readchars_wide() {
1383
1340
let wide_test = ~" 生锈的汤匙切肉汤hello生锈的汤匙切肉汤";
0 commit comments