diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-05-03 16:33:33 -0400 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-05-10 19:20:20 -0400 |
| commit | b05aae2d4151a5985d58758fcd46037fb39a5fb9 (patch) | |
| tree | c12b1b3738ade87f372a3388b13c698b1929d639 /src/libstd/fileinput.rs | |
| parent | cdc266e47d8ee63a1eaf29c775f2cbc5f3a61bb4 (diff) | |
| download | rust-b05aae2d4151a5985d58758fcd46037fb39a5fb9.tar.gz rust-b05aae2d4151a5985d58758fcd46037fb39a5fb9.zip | |
test: Use the new `for` protocol
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 { |
