From dd19bc27c1939a9c47f2e23989b32dad5f5c9265 Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Thu, 7 May 2015 20:47:59 -0400 Subject: [PATCH] Update fold to nightly build. --- src/fold/fold.rs | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/fold/fold.rs b/src/fold/fold.rs index cb3b47b42..a59def5ba 100644 --- a/src/fold/fold.rs +++ b/src/fold/fold.rs @@ -1,5 +1,5 @@ #![crate_name = "fold"] -#![feature(collections, core, old_io, old_path, rustc_private, unicode)] +#![feature(collections, rustc_private)] /* * This file is part of the uutils coreutils package. @@ -13,9 +13,9 @@ extern crate getopts; extern crate libc; -use std::old_io as io; -use std::old_io::fs::File; -use std::old_io::BufferedReader; +use std::fs::File; +use std::io::{BufRead, BufReader, Read, stdin, Write}; +use std::path::Path; #[path = "../common/util.rs"] #[macro_use] @@ -25,7 +25,7 @@ static NAME: &'static str = "fold"; static VERSION: &'static str = "1.0.0"; pub fn uumain(args: Vec) -> i32 { - let (args, obs_width) = handle_obsolete(args.as_slice()); + let (args, obs_width) = handle_obsolete(&args[..]); let program = args[0].clone(); let opts = [ @@ -36,7 +36,7 @@ pub fn uumain(args: Vec) -> i32 { getopts::optflag("V", "version", "output version information and exit") ]; - let matches = match getopts::getopts(args.tail(), &opts) { + let matches = match getopts::getopts(&args[1..], &opts) { Ok(m) => m, Err(f) => crash!(1, "{}", f) }; @@ -82,8 +82,8 @@ pub fn uumain(args: Vec) -> i32 { fn handle_obsolete(args: &[String]) -> (Vec, Option) { for (i, arg) in args.iter().enumerate() { - let slice = arg.as_slice(); - if slice.char_at(0) == '-' && slice.len() > 1 && slice.char_at(1).is_digit(10) { + let slice = &arg; + if slice.chars().next().unwrap() == '-' && slice.len() > 1 && slice.chars().nth(1).unwrap().is_digit(10) { return (args[..i].to_vec() + &args[i + 1..], Some(slice[1..].to_string())); } @@ -94,16 +94,16 @@ fn handle_obsolete(args: &[String]) -> (Vec, Option) { #[inline] fn fold(filenames: Vec, bytes: bool, spaces: bool, width: usize) { for filename in filenames.iter() { - let filename: &str = filename.as_slice(); + let filename: &str = &filename; let mut stdin_buf; let mut file_buf; - let buffer = BufferedReader::new( + let buffer = BufReader::new( if filename == "-" { - stdin_buf = io::stdio::stdin_raw(); - &mut stdin_buf as &mut Reader + stdin_buf = stdin(); + &mut stdin_buf as &mut Read } else { - file_buf = safe_unwrap!(File::open(&Path::new(filename))); - &mut file_buf as &mut Reader + file_buf = safe_unwrap!(File::open(Path::new(filename))); + &mut file_buf as &mut Read } ); fold_file(buffer, bytes, spaces, width); @@ -111,11 +111,9 @@ fn fold(filenames: Vec, bytes: bool, spaces: bool, width: usize) { } #[inline] -fn fold_file(file: BufferedReader, bytes: bool, spaces: bool, width: usize) { - let mut file = file; - for line in file.lines() { - let line_string = safe_unwrap!(line); - let mut line = line_string.as_slice(); +fn fold_file(mut file: BufReader, bytes: bool, spaces: bool, width: usize) { + let mut line = String::new(); + while safe_unwrap!(file.read_line(&mut line)) > 0 { if bytes { let len = line.len(); let mut i = 0; @@ -143,15 +141,15 @@ fn fold_file(file: BufferedReader, bytes: bool, spaces: bool, println!(""); continue; } - line = &line[..line.len() - 1]; len -= 1; + line.truncate(len); } let mut output = String::new(); let mut count = 0; for (i, ch) in line.chars().enumerate() { if count >= width { let (val, ncount) = { - let slice = output.as_slice(); + let slice = &output[..]; let (out, val, ncount) = if spaces && i + 1 < len { match rfind_whitespace(slice) {