diff options
Diffstat (limited to 'src/libextra/fileinput.rs')
| -rw-r--r-- | src/libextra/fileinput.rs | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/src/libextra/fileinput.rs b/src/libextra/fileinput.rs index ed38db1d686..f91260f4752 100644 --- a/src/libextra/fileinput.rs +++ b/src/libextra/fileinput.rs @@ -57,14 +57,14 @@ For more complicated uses (e.g. if one needs to pause iteration and resume it later), a `FileInput` instance can be constructed via the `from_vec`, `from_vec_raw` and `from_args` functions. -Once created, the `each_line` (from the `core::io::ReaderUtil` trait) +Once created, the `each_line` (from the `std::io::ReaderUtil` trait) and `each_line_state` methods allow one to iterate on the lines; the latter provides more information about the position within the iteration to the caller. It is possible (and safe) to skip lines and files using the `read_line` and `next_file` methods. Also, `FileInput` implements -`core::io::Reader`, and the state will be updated correctly while +`std::io::Reader`, and the state will be updated correctly while using any of those methods. E.g. the following program reads until an empty line, pauses for user @@ -96,12 +96,10 @@ total line count). #[allow(missing_doc)]; -use core::prelude::*; -use core::io::ReaderUtil; -use core::io; -use core::os; -use core::vec; +use std::io::ReaderUtil; +use std::io; +use std::os; /** A summary of the internal state of a `FileInput` object. `line_num` @@ -354,13 +352,13 @@ a literal `-`. */ // XXX: stupid, unclear name pub fn pathify(vec: &[~str], stdin_hyphen : bool) -> ~[Option<Path>] { - vec::map(vec, |&str : & ~str| { - if stdin_hyphen && str == ~"-" { + vec.iter().transform(|str| { + if stdin_hyphen && "-" == *str { None } else { - Some(Path(str)) + Some(Path(*str)) } - }) + }).collect() } /** @@ -410,18 +408,17 @@ pub fn input_vec_state(files: ~[Option<Path>], #[cfg(test)] mod test { - use core::prelude::*; use super::{FileInput, pathify, input_vec, input_vec_state}; - use core::io; - use core::uint; - use core::vec; + use std::io; + use std::uint; + use std::vec; fn make_file(path : &Path, contents: &[~str]) { let file = io::file_writer(path, [io::Create, io::Truncate]).get(); - for contents.each |&str| { + for contents.iter().advance |&str| { file.write_str(str); file.write_char('\n'); } @@ -448,7 +445,7 @@ mod test { |i| fmt!("tmp/lib-fileinput-test-fileinput-read-byte-%u.tmp", i)), true); // 3 files containing 0\n, 1\n, and 2\n respectively - for filenames.eachi |i, &filename| { + for filenames.iter().enumerate().advance |(i, &filename)| { make_file(filename.get_ref(), [fmt!("%u", i)]); } @@ -478,7 +475,7 @@ mod test { |i| fmt!("tmp/lib-fileinput-test-fileinput-read-%u.tmp", i)), true); // 3 files containing 1\n, 2\n, and 3\n respectively - for filenames.eachi |i, &filename| { + for filenames.iter().enumerate().advance |(i, &filename)| { make_file(filename.get_ref(), [fmt!("%u", i)]); } @@ -498,7 +495,7 @@ mod test { 3, |i| fmt!("tmp/lib-fileinput-test-input-vec-%u.tmp", i)), true); - for filenames.eachi |i, &filename| { + for filenames.iter().enumerate().advance |(i, &filename)| { let contents = vec::from_fn(3, |j| fmt!("%u %u", i, j)); make_file(filename.get_ref(), contents); @@ -518,7 +515,7 @@ mod test { 3, |i| fmt!("tmp/lib-fileinput-test-input-vec-state-%u.tmp", i)),true); - for filenames.eachi |i, &filename| { + for filenames.iter().enumerate().advance |(i, &filename)| { let contents = vec::from_fn(3, |j| fmt!("%u %u", i, j + 1)); make_file(filename.get_ref(), contents); @@ -582,7 +579,7 @@ mod test { 3, |i| fmt!("tmp/lib-fileinput-test-next-file-%u.tmp", i)),true); - for filenames.eachi |i, &filename| { + for filenames.iter().enumerate().advance |(i, &filename)| { let contents = vec::from_fn(3, |j| fmt!("%u %u", i, j + 1)); make_file(&filename.get(), contents); |
