diff options
| author | bors <bors@rust-lang.org> | 2013-05-10 17:56:02 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-05-10 17:56:02 -0700 |
| commit | 3e0400fb86170baff30282edcdccff73e243fd6e (patch) | |
| tree | ec7cc5de5ce7c80845c77fdcbb670cd54c120783 /src/libstd/fileinput.rs | |
| parent | d546493096f35e68cbcd9b5d3d7654e7a9345744 (diff) | |
| parent | 606bd75586419948f109de313ab37e31397ca7a3 (diff) | |
| download | rust-3e0400fb86170baff30282edcdccff73e243fd6e.tar.gz rust-3e0400fb86170baff30282edcdccff73e243fd6e.zip | |
auto merge of #6223 : alexcrichton/rust/issue-6183, r=pcwalton
Closes #6183. The first commit changes the compiler's method of treating a `for` loop, and all the remaining commits are just dealing with the fallout. The biggest fallout was the `IterBytes` trait, although it's really a whole lot nicer now because all of the `iter_bytes_XX` methods are just and-ed together. Sadly there was a huge amount of stuff that's `cfg(stage0)` gated, but whoever lands the next snapshot is going to have a lot of fun deleting all this code!
Diffstat (limited to 'src/libstd/fileinput.rs')
| -rw-r--r-- | src/libstd/fileinput.rs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/libstd/fileinput.rs b/src/libstd/fileinput.rs index 90774d19595..2c5cbc1cbf9 100644 --- a/src/libstd/fileinput.rs +++ b/src/libstd/fileinput.rs @@ -256,10 +256,21 @@ impl FileInput { (line numbers and file names, see documentation for `FileInputState`). Otherwise identical to `lines_each`. */ + #[cfg(stage0)] pub fn each_line_state(&self, f: &fn(&str, FileInputState) -> bool) { self.each_line(|line| f(line, copy self.fi.state)); } + /** + Apply `f` to each line successively, along with some state + (line numbers and file names, see documentation for + `FileInputState`). Otherwise identical to `lines_each`. + */ + #[cfg(not(stage0))] + pub fn each_line_state(&self, + f: &fn(&str, FileInputState) -> bool) -> bool { + self.each_line(|line| f(line, copy self.fi.state)) + } /** @@ -367,10 +378,22 @@ reading from `stdin`). Fails when attempting to read from a file that can't be opened. */ +#[cfg(stage0)] pub fn input(f: &fn(&str) -> bool) { let mut i = FileInput::from_args(); i.each_line(f); } +/** +Iterate directly over the command line arguments (no arguments implies +reading from `stdin`). + +Fails when attempting to read from a file that can't be opened. +*/ +#[cfg(not(stage0))] +pub fn input(f: &fn(&str) -> bool) -> bool { + let mut i = FileInput::from_args(); + i.each_line(f) +} /** Iterate directly over the command line arguments (no arguments @@ -379,20 +402,44 @@ provided at each call. Fails when attempting to read from a file that can't be opened. */ +#[cfg(stage0)] pub fn input_state(f: &fn(&str, FileInputState) -> bool) { let mut i = FileInput::from_args(); i.each_line_state(f); } +/** +Iterate directly over the command line arguments (no arguments +implies reading from `stdin`) with the current state of the iteration +provided at each call. + +Fails when attempting to read from a file that can't be opened. +*/ +#[cfg(not(stage0))] +pub fn input_state(f: &fn(&str, FileInputState) -> bool) -> bool { + let mut i = FileInput::from_args(); + i.each_line_state(f) +} /** Iterate over a vector of files (an empty vector implies just `stdin`). Fails when attempting to read from a file that can't be opened. */ +#[cfg(stage0)] pub fn input_vec(files: ~[Option<Path>], f: &fn(&str) -> bool) { let mut i = FileInput::from_vec(files); i.each_line(f); } +/** +Iterate over a vector of files (an empty vector implies just `stdin`). + +Fails when attempting to read from a file that can't be opened. +*/ +#[cfg(not(stage0))] +pub fn input_vec(files: ~[Option<Path>], f: &fn(&str) -> bool) -> bool { + let mut i = FileInput::from_vec(files); + i.each_line(f) +} /** Iterate over a vector of files (an empty vector implies just `stdin`) @@ -400,11 +447,24 @@ with the current state of the iteration provided at each call. Fails when attempting to read from a file that can't be opened. */ +#[cfg(stage0)] pub fn input_vec_state(files: ~[Option<Path>], f: &fn(&str, FileInputState) -> bool) { let mut i = FileInput::from_vec(files); i.each_line_state(f); } +/** +Iterate over a vector of files (an empty vector implies just `stdin`) +with the current state of the iteration provided at each call. + +Fails when attempting to read from a file that can't be opened. +*/ +#[cfg(not(stage0))] +pub fn input_vec_state(files: ~[Option<Path>], + f: &fn(&str, FileInputState) -> bool) -> bool { + let mut i = FileInput::from_vec(files); + i.each_line_state(f) +} #[cfg(test)] mod test { |
