std::io: Add Buffer.lines(), change .bytes() api

-   `Buffer.lines()` returns `LineIterator` which yields line using
    `.read_line()`.
-   `Reader.bytes()` now takes `&mut self` instead of `self`.
-   `Reader.read_until()` swallows `EndOfFile`. This also affects
    `.read_line()`.
This commit is contained in:
klutzy 2013-12-08 16:12:07 +09:00
parent b8b16ae099
commit 5a93d12e01
8 changed files with 141 additions and 76 deletions

View file

@ -77,8 +77,7 @@ fn read_line() {
for _ in range(0, 3) {
let mut reader = BufferedReader::new(File::open(&path).unwrap());
while !reader.eof() {
reader.read_line();
for _line in reader.lines() {
}
}
}

View file

@ -188,14 +188,7 @@ fn main() {
// reading the sequence of interest
let mut proc_mode = false;
loop {
let line = {
let _guard = io::ignore_io_error();
match rdr.read_line() {
Some(ln) => ln,
None => break,
}
};
for line in rdr.lines() {
let line = line.trim().to_owned();
if line.len() == 0u { continue; }

View file

@ -18,7 +18,6 @@ use std::io;
use std::io::stdio::StdReader;
use std::io::buffered::BufferedReader;
use std::os;
use std::uint;
use std::unstable::intrinsics::cttz16;
use std::vec;
@ -72,10 +71,7 @@ impl Sudoku {
assert!(reader.read_line().unwrap() == ~"9,9"); /* assert first line is exactly "9,9" */
let mut g = vec::from_fn(10u, { |_i| ~[0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8] });
loop {
let line = match reader.read_line() {
Some(ln) => ln, None => break
};
for line in reader.lines() {
let comps: ~[&str] = line.trim().split(',').collect();
if comps.len() == 3u {