diff --git a/src/echo/echo.rs b/src/echo/echo.rs index d66abc859..ea9c53720 100644 --- a/src/echo/echo.rs +++ b/src/echo/echo.rs @@ -1,5 +1,5 @@ #![crate_name = "echo"] -#![feature(collections, core, old_io, rustc_private)] +#![feature(rustc_private, str_char)] /* * This file is part of the uutils coreutils package. @@ -13,8 +13,6 @@ extern crate getopts; extern crate libc; -use std::old_io::{print, println}; -use std::num::from_str_radix; use std::str::from_utf8; #[path = "../common/util.rs"] @@ -32,7 +30,7 @@ struct EchoOptions { #[inline(always)] fn to_char(bytes: &Vec, base: u32) -> char { - from_str_radix::(from_utf8(bytes.as_slice()).unwrap(), base).unwrap() as u8 as char + usize::from_str_radix(from_utf8(bytes.as_ref()).unwrap(), base).unwrap() as u8 as char } #[inline(always)] @@ -60,7 +58,7 @@ fn convert_str(string: &[u8], index: usize, base: u32) -> (char, usize) { }; let mut bytes = vec!(); - for offset in range(0usize, max_digits) { + for offset in (0usize .. max_digits) { if string.len() <= index + offset as usize { break; } @@ -83,7 +81,7 @@ fn parse_options(args: Vec, options: &mut EchoOptions) -> Option { print_help(&program); return None; @@ -96,10 +94,9 @@ fn parse_options(args: Vec, options: &mut EchoOptions) -> Option options.escape = true, "-E" => options.escape = false, _ => { - if arg.len() > 1 && arg.as_slice().char_at(0) == '-' { + if arg.len() > 1 && arg.char_at(0) == '-' { let mut newopts = options.clone(); - let argptr: *const String = &arg; // escape from the borrow checker - for ch in unsafe { (*argptr).as_slice() }.chars().skip(1) { + for ch in arg.chars().skip(1) { match ch { 'h' => { print_help(&program); @@ -113,7 +110,7 @@ fn parse_options(args: Vec, options: &mut EchoOptions) -> Option newopts.escape = true, 'E' => newopts.escape = false, _ => { - echo_args.push(arg); + echo_args.push(arg.clone()); continue 'argloop; } } @@ -142,8 +139,8 @@ fn print_help(program: &String) { println!(" {0} [SHORT-OPTION]... [STRING]...", *program); println!(" {0} LONG-OPTION", *program); println!(""); - println(getopts::usage("Echo the STRING(s) to standard output.", &opts).as_slice()); - println("If -e is in effect, the following sequences are recognized: + println!("{}", getopts::usage("Echo the STRING(s) to standard output.", &opts)); + println!("{}", "If -e is in effect, the following sequences are recognized: \\\\ backslash \\a alert (BEL) @@ -178,7 +175,7 @@ pub fn uumain(args: Vec) -> i32 { let string = free.connect(" "); if options.escape { let mut prev_was_slash = false; - let mut iter = string.as_slice().chars().enumerate(); + let mut iter = string.chars().enumerate(); loop { match iter.next() { Some((index, c)) => { @@ -207,7 +204,7 @@ pub fn uumain(args: Vec) -> i32 { print!("\\x"); } else { print!("{}", c); - for _ in range(0, num_char_used) { + for _ in (0 .. num_char_used) { iter.next(); // consume used characters } } @@ -218,7 +215,7 @@ pub fn uumain(args: Vec) -> i32 { print!("\0"); } else { print!("{}", c); - for _ in range(0, num_char_used) { + for _ in (0 .. num_char_used) { iter.next(); // consume used characters } } @@ -229,7 +226,7 @@ pub fn uumain(args: Vec) -> i32 { print!("\\{}", c); } else { print!("{}", esc_c); - for _ in range(1, num_char_used) { + for _ in (1 .. num_char_used) { iter.next(); // consume used characters } } @@ -241,7 +238,7 @@ pub fn uumain(args: Vec) -> i32 { } } } else { - print(string.as_slice()); + print!("{}", string); } }