diff --git a/base64/base64.rs b/base64/base64.rs index b1898e4d8..7ac2e032a 100644 --- a/base64/base64.rs +++ b/base64/base64.rs @@ -97,16 +97,16 @@ fn decode(input: &mut Reader, ignore_garbage: bool) { Err(f) => fail!(f.to_str()) }; - to_decode = str::replace(to_decode, "\n", ""); + to_decode = str::replace(to_decode.as_slice(), "\n", ""); if ignore_garbage { let standard_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - to_decode = to_decode + to_decode = to_decode.as_slice() .trim_chars(|c| !standard_chars.contains_char(c)) - .to_owned(); + .into_owned() } - match to_decode.from_base64() { + match to_decode.as_slice().from_base64() { Ok(bytes) => { let mut out = stdout(); @@ -148,7 +148,7 @@ fn encode(input: &mut Reader, line_wrap: uint) { // compatibility. let final = encoded.replace("\r", ""); - println(final); + println(final.as_slice()); } fn help(progname: &str, usage: &str) { diff --git a/basename/basename.rs b/basename/basename.rs index 58a5a3a15..dd1434097 100644 --- a/basename/basename.rs +++ b/basename/basename.rs @@ -24,8 +24,8 @@ static NAME: &'static str = "basename"; static VERSION: &'static str = "1.0.0"; fn main() { - let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); - let program = strip_dir(os::args().get(0)); + let args = os::args(); + let program = strip_dir(args.get(0).as_slice()); // // Argument parsing @@ -52,20 +52,20 @@ fn main() { } if matches.opt_present("version") { - println(program + " " + VERSION); + println!("{} {}", program, VERSION); return; } // too few arguments if args.len() < 2 { - println(program + ": missing operand"); - println("Try `" + program + " --help' for more information."); + println!("{}: {}", program, "missing operand"); + println!("Try '{} --help' for more information.", program); return; } // too many arguments else if args.len() > 3 { - println(program + ": extra operand `" + args.get(3).as_slice() + "'"); - println("Try `" + program + " --help' for more information."); + println!("{}: extra operand '{}'", program, args.get(3)); + println!("Try '{} --help' for more information.", program); return; } @@ -73,19 +73,19 @@ fn main() { // Main Program Processing // - let fullname = args.get(1).clone(); + let fullname = args.get(1); - let mut name = strip_dir(&fullname.as_slice().to_owned()); + let mut name = strip_dir(fullname.as_slice()); if args.len() > 2 { let suffix = args.get(2).clone(); - name = strip_suffix(&name, &suffix.to_owned()); + name = strip_suffix(name.as_slice(), suffix.as_slice()); } - println(name); + println(name.as_slice()); } -fn strip_dir(fullname: &~str) -> ~str { +fn strip_dir(fullname: &str) -> StrBuf { let mut name = StrBuf::new(); for c in fullname.chars().rev() { @@ -98,14 +98,14 @@ fn strip_dir(fullname: &~str) -> ~str { return name.as_slice().chars().rev().collect(); } -fn strip_suffix(name: &~str, suffix: &~str) -> ~str { +fn strip_suffix(name: &str, suffix: &str) -> StrBuf { if name == suffix { - return name.clone(); + return name.into_strbuf(); } - if name.ends_with(*suffix) { - return name.slice_to(name.len() - suffix.len()).into_owned(); + if name.ends_with(suffix) { + return name.slice_to(name.len() - suffix.len()).into_strbuf(); } - return name.clone(); + return name.into_strbuf(); } diff --git a/cat/cat.rs b/cat/cat.rs index 2ae2d4c36..a86fee6c0 100644 --- a/cat/cat.rs +++ b/cat/cat.rs @@ -103,7 +103,7 @@ pub fn exec(files: Vec, number: NumberingMode, show_nonprint: bool, show let is_numbering = number == NumberAll || number == NumberNonEmpty; for path in files.iter() { - let mut reader = match open(path.to_owned()) { + let mut reader = match open(path.as_slice()) { Some(f) => f, None => { continue } }; @@ -158,7 +158,7 @@ pub fn exec(files: Vec, number: NumberingMode, show_nonprint: bool, show let mut buf = ~[0, .. 1024 * 64]; // passthru mode for path in files.iter() { - let mut reader = match open(path.to_owned()) { + let mut reader = match open(path.as_slice()) { Some(f) => f, None => { continue } }; @@ -175,7 +175,7 @@ pub fn exec(files: Vec, number: NumberingMode, show_nonprint: bool, show } } -fn open(path: ~str) -> Option> { +fn open(path: &str) -> Option> { if "-" == path { return Some(box stdin_raw() as Box); } diff --git a/du/du.rs b/du/du.rs index ea12d1f4e..8f65145f7 100644 --- a/du/du.rs +++ b/du/du.rs @@ -32,7 +32,7 @@ static VERSION: &'static str = "1.0.0"; struct Options { all: bool, - program_name: ~str, + program_name: StrBuf, max_depth: Option, total: bool, separate_dirs: bool, @@ -268,7 +268,7 @@ ers of 1000).", None => 1024 }; - let convert_size = |size: u64| -> ~str { + let convert_size = |size: u64| -> StrBuf { if matches.opt_present("human-readable") || matches.opt_present("si") { if size > MB { format!("{:.1f}M", (size as f64) / (MB as f64)) diff --git a/echo/echo.rs b/echo/echo.rs index 6486fbf36..c1979d61d 100644 --- a/echo/echo.rs +++ b/echo/echo.rs @@ -118,7 +118,7 @@ fn main() { let string = matches.free.connect(" "); if matches.opt_present("e") { let mut prev_was_slash = false; - let mut iter = string.chars().enumerate(); + let mut iter = string.as_slice().chars().enumerate(); loop { match iter.next() { Some((index, c)) => { @@ -142,7 +142,7 @@ fn main() { 't' => print_char('\t'), 'v' => print_char('\x0B'), 'x' => { - let (c, num_char_used) = convert_str(string, index + 1, 16u); + let (c, num_char_used) = convert_str(string.as_slice(), index + 1, 16u); if num_char_used == 0 { print_char('\\'); print_char('x'); @@ -154,7 +154,7 @@ fn main() { } }, '0' => { - let (c, num_char_used) = convert_str(string, index + 1, 8u); + let (c, num_char_used) = convert_str(string.as_slice(), index + 1, 8u); if num_char_used == 0 { print_char('\\'); print_char('0'); @@ -176,7 +176,7 @@ fn main() { } } } else { - print(string); + print(string.as_slice()); } } diff --git a/env/env.rs b/env/env.rs index 15f0c1e98..ed7afb63b 100644 --- a/env/env.rs +++ b/env/env.rs @@ -16,9 +16,9 @@ struct options { ignore_env: bool, null: bool, - unsets: Vec<~str>, - sets: Vec<(~str, ~str)>, - program: Vec<~str> + unsets: Vec, + sets: Vec<(StrBuf, StrBuf)>, + program: Vec } fn usage(prog: &str) { @@ -77,7 +77,7 @@ fn main() { if wait_cmd { // we still accept NAME=VAL here but not other options - let mut sp = opt.splitn('=', 1); + let mut sp = opt.as_slice().splitn('=', 1); let name = sp.next(); let value = sp.next(); @@ -91,7 +91,7 @@ fn main() { break; } } - } else if opt.starts_with("--") { + } else if opt.as_slice().starts_with("--") { match opt.as_slice() { "--help" => { usage(prog); return } "--version" => { version(); return } @@ -113,7 +113,7 @@ fn main() { return } } - } else if opt.starts_with("-") { + } else if opt.as_slice().starts_with("-") { if opt.len() == 0 { // implies -i and stop parsing opts wait_cmd = true; @@ -121,7 +121,7 @@ fn main() { continue; } - let mut chars = opt.chars(); + let mut chars = opt.as_slice().chars(); chars.next(); for c in chars { @@ -148,7 +148,7 @@ fn main() { } } else { // is it a NAME=VALUE like opt ? - let mut sp = opt.splitn('=', 1); + let mut sp = opt.as_slice().splitn('=', 1); let name = sp.next(); let value = sp.next(); diff --git a/fold/fold.rs b/fold/fold.rs index 9f40063ea..483d212e4 100644 --- a/fold/fold.rs +++ b/fold/fold.rs @@ -82,24 +82,24 @@ fn main() { } } -fn handle_obsolete(args: ~[~str]) -> (~[~str], Option<~str>) { - let mut args: Vec<~str> = args.move_iter().collect(); +fn handle_obsolete(args: &[StrBuf]) -> (Vec, Option) { + let mut args = Vec::::from_slice(args); let mut i = 0; while i < args.len() { - if args.get(i).char_at(0) == '-' && args.get(i).len() > 1 && args.get(i).char_at(1).is_digit() { - return (args.as_slice().to_owned(), - Some(args.remove(i).unwrap().slice_from(1).to_owned())); + if args.get(i).as_slice().char_at(0) == '-' && args.get(i).len() > 1 && args.get(i).as_slice().char_at(1).is_digit() { + return (args.clone(), + Some(args.remove(i).unwrap().as_slice().slice_from(1).to_owned())); } i += 1; } - (args.as_slice().to_owned(), None) + (args, None) } fn fold(filenames: Vec, bytes: bool, spaces: bool, width: uint) { for filename in filenames.iter() { let filename: &str = filename.as_slice(); let buffer = BufferedReader::new( - if filename == "-".to_owned() { + if filename == "-" { box io::stdio::stdin_raw() as Box } else { box safe_unwrap!(File::open(&Path::new(filename))) as Box @@ -117,7 +117,7 @@ fn fold_file(file: BufferedReader, bytes: bool, spaces: bool, println!(""); continue; } - let line = line.slice_to(line.len() - 1); + let line = line.as_slice().slice_to(line.len() - 1); if bytes { let mut i = 0; while i < line.len() { @@ -173,7 +173,7 @@ fn fold_file(file: BufferedReader, bytes: bool, spaces: bool, match slice.rfind(|ch: char| ch.is_whitespace()) { Some(m) => { let routput = slice.slice_from(m + 1).to_owned(); - let ncount = routput.chars().fold(0, |out, ch: char| out + if ch == '\t' { 8 } else { 1 }); + let ncount = routput.as_slice().chars().fold(0, |out, ch: char| out + if ch == '\t' { 8 } else { 1 }); (slice.slice_to(m + 1), routput, ncount) }, None => (slice, "".to_owned(), 0) diff --git a/head/head.rs b/head/head.rs index 27fd08911..8b6ed08f4 100644 --- a/head/head.rs +++ b/head/head.rs @@ -26,7 +26,7 @@ fn main () { let mut line_count = 10u; // handle obsolete -number syntax - let options = match obsolete(os::args().tail().to_owned()) { + let options = match obsolete(os::args().tail()) { (args, Some(n)) => { line_count = n; args }, (args, None) => args }; @@ -96,14 +96,14 @@ fn main () { // // In case is found, the options vector will get rid of that object so that // getopts works correctly. -fn obsolete (options: ~[~str]) -> (~[~str], Option) { - let mut options: Vec<~str> = options.move_iter().collect(); +fn obsolete (options: &[StrBuf]) -> (Vec, Option) { + let mut options: Vec = Vec::from_slice(options); let mut a = 0; let b = options.len(); - let mut current; while a < b { - current = options.get(a).clone(); + let current = options.get(a).clone(); + let current = current.as_slice(); if current.len() > 1 && current[0] == '-' as u8 { let len = current.len(); @@ -115,7 +115,7 @@ fn obsolete (options: ~[~str]) -> (~[~str], Option) { if pos == len - 1 { options.remove(a); let number : Option = from_str(current.slice(1,len)); - return (options.as_slice().to_owned(), Some(number.unwrap())); + return (options, Some(number.unwrap())); } } } @@ -123,7 +123,7 @@ fn obsolete (options: ~[~str]) -> (~[~str], Option) { a += 1; }; - (options.as_slice().to_owned(), None) + (options, None) } fn head (reader: &mut BufferedReader, line_count:uint) { diff --git a/hostid/hostid.rs b/hostid/hostid.rs index f616ef622..4951940ab 100644 --- a/hostid/hostid.rs +++ b/hostid/hostid.rs @@ -52,7 +52,7 @@ extern { fn main() { let args: Vec = os::args().iter().map(|x| x.to_strbuf()).collect(); - let opts = ~[ + let opts = [ optflag("", "help", "display this help and exit"), optflag("", "version", "output version information and exit"), ]; @@ -87,9 +87,8 @@ fn version() { println!("{} {}", NAME, VERSION); } -fn get_help_text(progname: &str, usage: &str) -> ~str { - let msg = format!("Usage: \n {0} {1}", progname, usage); - msg +fn get_help_text(progname: &str, usage: &str) -> StrBuf { + format!("Usage: \n {0} {1}", progname, usage) } fn help(progname: &str, usage: &str) { diff --git a/hostname/hostname.rs b/hostname/hostname.rs index 3292e4a2b..9155d7b5d 100644 --- a/hostname/hostname.rs +++ b/hostname/hostname.rs @@ -36,31 +36,31 @@ fn main () { let matches = match getopts(args.tail(), options) { Ok(m) => { m } - _ => { help_menu(program, options); return; } + _ => { help_menu(program.as_slice(), options); return; } }; if matches.opt_present("h") { - help_menu(program, options); + help_menu(program.as_slice(), options); return } if matches.opt_present("V") { version(); return } match matches.free.len() { 0 => { - let hostname: ~str = xgethostname(); + let hostname = xgethostname(); if matches.opt_present("s") { - let pos = hostname.find_str("."); + let pos = hostname.as_slice().find_str("."); if pos.is_some() { - println!("{:s}", hostname.slice_to(pos.unwrap())); + println!("{:s}", hostname.as_slice().slice_to(pos.unwrap())); return; } } - println!("{:s}", hostname); + println!("{:s}", hostname.as_slice()); } - 1 => { xsethostname( &matches.free.last().unwrap().as_slice().to_owned() ) } - _ => { help_menu(program, options); } + 1 => { xsethostname( matches.free.last().unwrap().as_slice() ) } + _ => { help_menu(program.as_slice(), options); } }; } @@ -77,7 +77,7 @@ fn help_menu(program: &str, options: &[getopts::OptGroup]) { print!("{:s}", usage("Print or set the system's host name.", options)); } -fn xgethostname() -> ~str { +fn xgethostname() -> StrBuf { let namelen = 256u; let mut name = Vec::from_elem(namelen, 0u8); @@ -95,7 +95,7 @@ fn xgethostname() -> ~str { str::from_utf8(name.slice_to(last_char)).unwrap().to_owned() } -fn xsethostname(name: &~str) { +fn xsethostname(name: &str) { let vec_name: Vec = name.bytes().map(|c| c as i8).collect(); let err = unsafe { @@ -103,6 +103,6 @@ fn xsethostname(name: &~str) { }; if err != 0 { - println!("Cannot set hostname to {:s}", *name); + println!("Cannot set hostname to {:s}", name); } } diff --git a/kill/kill.rs b/kill/kill.rs index 076f61edc..97e2e681a 100644 --- a/kill/kill.rs +++ b/kill/kill.rs @@ -121,12 +121,12 @@ fn table() { } } -fn print_signal(signal_name_or_value: ~str) { +fn print_signal(signal_name_or_value: &str) { for signal in ALL_SIGNALS.iter() { - if signal.name == signal_name_or_value || ("SIG" + signal.name) == signal_name_or_value { + if signal.name == signal_name_or_value || (format!("SIG{}", signal.name).as_slice()) == signal_name_or_value { println!("{}", signal.value) exit!(EXIT_OK) - } else if signal_name_or_value == signal.value.to_str() { + } else if signal_name_or_value == signal.value.to_str().as_slice() { println!("{}", signal.name); exit!(EXIT_OK) } @@ -151,27 +151,26 @@ fn print_signals() { fn list(arg: Option) { match arg { - Some(x) => print_signal(x.to_owned()), + Some(x) => print_signal(x.as_slice()), None => print_signals(), }; } -fn get_help_text(progname: &str, usage: &str) -> ~str { - let msg = format!("Usage: \n {0} {1}", progname, usage); - msg +fn get_help_text(progname: &str, usage: &str) -> StrBuf { + format!("Usage: \n {0} {1}", progname, usage) } fn help(progname: &str, usage: &str) { println!("{}", get_help_text(progname, usage)); } -fn signal_by_name_or_value(signal_name_or_value:~str) -> Option { - if signal_name_or_value == "0".to_owned() { +fn signal_by_name_or_value(signal_name_or_value: &str) -> Option { + if signal_name_or_value == "0" { return Some(0); } for signal in ALL_SIGNALS.iter() { - let long_name = "SIG" + signal.name; - if signal.name == signal_name_or_value || (signal_name_or_value == signal.value.to_str()) || (long_name == signal_name_or_value) { + let long_name = format!("SIG{}", signal.name); + if signal.name == signal_name_or_value || (signal_name_or_value == signal.value.to_str().as_slice()) || (long_name.as_slice() == signal_name_or_value) { return Some(signal.value); } } @@ -179,7 +178,7 @@ fn signal_by_name_or_value(signal_name_or_value:~str) -> Option { } fn kill(signalname: &str, pids: std::vec::Vec) { - let optional_signal_value = signal_by_name_or_value(signalname.to_owned()); + let optional_signal_value = signal_by_name_or_value(signalname); let signal_value = match optional_signal_value { Some(x) => x, None => crash!(EXIT_ERR, "unknown signal name {}", signalname) diff --git a/logname/logname.rs b/logname/logname.rs index 8bbf7a908..72aff7554 100644 --- a/logname/logname.rs +++ b/logname/logname.rs @@ -18,7 +18,7 @@ extern crate getopts; extern crate libc; -use std::io::{print, println}; +use std::io::print; use std::os; use std::str; use libc::c_char; @@ -30,7 +30,7 @@ extern { pub fn getlogin() -> *libc::c_char; } -unsafe fn get_userlogin() -> ~str { +unsafe fn get_userlogin() -> StrBuf { let login: *libc::c_char = getlogin(); str::raw::from_c_str(login) @@ -40,7 +40,7 @@ static NAME: &'static str = "logname"; static VERSION: &'static str = "1.0.0"; fn version() { - println(NAME + " " + VERSION); + println!("{} {}", NAME, VERSION); } fn main() { diff --git a/md5sum/md5sum.rs b/md5sum/md5sum.rs index fce9218da..ba4305979 100644 --- a/md5sum/md5sum.rs +++ b/md5sum/md5sum.rs @@ -84,7 +84,7 @@ fn md5sum(files: Vec, binary: bool, check: bool, tag: bool, status: bool for filename in files.iter() { let filename: &str = filename.as_slice(); let mut file = BufferedReader::new( - if filename == "-".to_owned() { + if filename == "-" { box stdin_raw() as Box } else { box safe_unwrap!(File::open(&Path::new(filename))) as Box @@ -95,9 +95,9 @@ fn md5sum(files: Vec, binary: bool, check: bool, tag: bool, status: bool //let mut buffer = BufferedReader::new(file); for (i, line) in buffer.lines().enumerate() { let line = safe_unwrap!(line); - let (ck_filename, sum) = match from_gnu(line, bytes) { + let (ck_filename, sum) = match from_gnu(line.as_slice(), bytes) { Some(m) => m, - None => match from_bsd(line, bytes) { + None => match from_bsd(line.as_slice(), bytes) { Some(m) => m, None => { bad_format += 1; @@ -112,7 +112,7 @@ fn md5sum(files: Vec, binary: bool, check: bool, tag: bool, status: bool } }; let real_sum = calc_sum(&mut md5, &mut safe_unwrap!(File::open(&Path::new(ck_filename))), binary); - if sum == real_sum { + if sum == real_sum.as_slice() { if !quiet { println!("{}: OK", ck_filename); } @@ -145,15 +145,15 @@ fn md5sum(files: Vec, binary: bool, check: bool, tag: bool, status: bool } } -fn calc_sum(md5: &mut crypto::md5::Md5, file: &mut Reader, binary: bool) -> ~str { +fn calc_sum(md5: &mut crypto::md5::Md5, file: &mut Reader, binary: bool) -> StrBuf { let data = if binary { - (safe_unwrap!(file.read_to_end())).as_slice().to_owned() + (safe_unwrap!(file.read_to_end())) } else { (safe_unwrap!(file.read_to_str())).into_bytes() }; md5.reset(); - md5.input(data); + md5.input(data.as_slice()); md5.result_str() } diff --git a/mkdir/mkdir.rs b/mkdir/mkdir.rs index 4d4084bcf..6755b02fd 100644 --- a/mkdir/mkdir.rs +++ b/mkdir/mkdir.rs @@ -89,8 +89,7 @@ fn print_help(opts: &[getopts::OptGroup]) { println!("mkdir v{} - make a new directory with the given path", VERSION); println!(""); println!("Usage:"); - print!("{}", getopts::usage("Create the given DIRECTORY(ies)" + - " if they do not exist", opts)); + print!("{}", getopts::usage("Create the given DIRECTORY(ies) if they do not exist", opts)); } /** diff --git a/paste/paste.rs b/paste/paste.rs index e20aea39f..0a33fe5c7 100644 --- a/paste/paste.rs +++ b/paste/paste.rs @@ -66,23 +66,26 @@ fn paste(filenames: Vec, serial: bool, delimiters: &str) { } ) ).collect(); - let delimiters: Vec<~str> = delimiters.chars().map(|x| x.to_str()).collect(); + let delimiters: Vec = delimiters.chars().map(|x| x.to_str()).collect(); let mut delim_count = 0; if serial { for file in files.mut_iter() { - let mut output = "".to_owned(); + let mut output = StrBuf::new(); loop { - output = output + match file.read_line() { - Ok(line) => line.trim_right() + delimiters.get(delim_count % delimiters.len()).clone(), + match file.read_line() { + Ok(line) => { + output.push_str(line.as_slice().trim_right()); + output.push_str(delimiters.get(delim_count % delimiters.len()).as_slice()); + } Err(f) => if f.kind == io::EndOfFile { break } else { crash!(1, "{}", f.to_str()) } - }; + } delim_count += 1; } - println!("{}", output.slice_to(output.len() - 1)); + println!("{}", output.as_slice().slice_to(output.len() - 1)); } } else { let mut eof = Vec::from_elem(files.len(), false); @@ -94,7 +97,7 @@ fn paste(filenames: Vec, serial: bool, delimiters: &str) { eof_count += 1; } else { match file.read_line() { - Ok(line) => output = output + line.slice_to(line.len() - 1), + Ok(line) => output.push_str(line.as_slice().slice_to(line.len() - 1)), Err(f) => if f.kind == io::EndOfFile { *eof.get_mut(i) = true; eof_count += 1; @@ -103,13 +106,13 @@ fn paste(filenames: Vec, serial: bool, delimiters: &str) { } } } - output = output + delimiters.get(delim_count % delimiters.len()).clone(); + output.push_str(delimiters.get(delim_count % delimiters.len()).as_slice()); delim_count += 1; } if files.len() == eof_count { break; } - println!("{}", output.slice_to(output.len() - 1)); + println!("{}", output.as_slice().slice_to(output.len() - 1)); delim_count = 0; } } diff --git a/printenv/printenv.rs b/printenv/printenv.rs index 92a4770ae..fe3871827 100644 --- a/printenv/printenv.rs +++ b/printenv/printenv.rs @@ -72,7 +72,7 @@ pub fn exec(args: Vec, separator: &str) { for env_var in args.iter() { match os::getenv(env_var.as_slice()) { Some(var) => { - print(var); + print(var.as_slice()); print(separator); } _ => () diff --git a/rm/rm.rs b/rm/rm.rs index 1d7286efa..468eb2127 100644 --- a/rm/rm.rs +++ b/rm/rm.rs @@ -192,9 +192,9 @@ fn remove_file(path: &Path, name: &str, interactive: InteractiveMode, verbose: b fn prompt_file(path: &Path, name: &str) -> bool { if path.is_dir() { - prompt(format!("Remove directory '{}'? ", name)) + prompt(format!("Remove directory '{}'? ", name).as_slice()) } else { - prompt(format!("Remove file '{}'? ", name)) + prompt(format!("Remove file '{}'? ", name).as_slice()) } } @@ -207,7 +207,7 @@ fn read_prompt() -> bool { stdio::flush(); match BufferedReader::new(stdin()).read_line() { Ok(line) => { - match line.char_at(0) { + match line.as_slice().char_at(0) { 'y' | 'Y' => true, 'n' | 'N' => false, _ => { diff --git a/seq/seq.rs b/seq/seq.rs index cf7918bea..e73efd8b3 100644 --- a/seq/seq.rs +++ b/seq/seq.rs @@ -21,14 +21,14 @@ fn print_usage(opts: ~[getopts::OptGroup]) { println!("{:s}", getopts::usage("Print sequences of numbers", opts)); } -fn parse_float(s: &str) -> Result{ +fn parse_float(s: &str) -> Result{ match from_str(s) { Some(n) => Ok(n), None => Err(format!("seq: invalid floating point argument: {:s}", s)) } } -fn escape_sequences(s: &str) -> ~str { +fn escape_sequences(s: &str) -> StrBuf { s.replace("\\n", "\n"). replace("\\t", "\t") } @@ -96,7 +96,7 @@ fn done_printing(next: f32, step: f32, last: f32) -> bool { } } -fn print_seq(first: f32, step: f32, last: f32, separator: ~str, terminator: ~str, pad: bool) { +fn print_seq(first: f32, step: f32, last: f32, separator: StrBuf, terminator: StrBuf, pad: bool) { let mut i = first; let maxlen = first.max(last).to_str().len(); while !done_printing(i, step, last) { diff --git a/sleep/sleep.rs b/sleep/sleep.rs index 27e26c80a..f85ab8faf 100644 --- a/sleep/sleep.rs +++ b/sleep/sleep.rs @@ -67,17 +67,17 @@ fn sleep(args: Vec) { let (arg, suffix_time) = match match_suffix(arg.as_slice()) { Ok(m) => m, Err(f) => { - crash!(1, "{}", f) + crash!(1, "{}", f.to_strbuf()) } }; let num = if suffix_time == 0 { 0.0 } else { - match num::from_str_radix::((arg), 10) { + match num::from_str_radix::((arg.as_slice()), 10) { Some(m) => m, None => { - crash!(1, "Invalid time interval '{}'", arg) + crash!(1, "Invalid time interval '{}'", arg.to_strbuf()) } } }; @@ -86,7 +86,7 @@ fn sleep(args: Vec) { timer::sleep((sleep_time * 1000.0) as u64); } -fn match_suffix(arg: &str) -> Result<(~str, int), ~str> { +fn match_suffix(arg: &str) -> Result<(StrBuf, int), StrBuf> { let result = match (arg).char_at_reverse(0) { 's' | 'S' => 1, 'm' | 'M' => 60, @@ -94,7 +94,7 @@ fn match_suffix(arg: &str) -> Result<(~str, int), ~str> { 'd' | 'D' => 60 * 60 * 24, val => { if !val.is_alphabetic() { - return Ok(((arg).to_owned(), 1)) + return Ok((arg.to_strbuf(), 1)) } else { return Err(format!("Invalid time interval '{}'", arg)) } diff --git a/tac/tac.rs b/tac/tac.rs index 2e6dacc76..c2642a354 100644 --- a/tac/tac.rs +++ b/tac/tac.rs @@ -79,21 +79,24 @@ fn tac(filenames: Vec, before: bool, _: bool, separator: &str) { } ); let mut data = crash_if_err!(1, file.read_to_str()); - if data.ends_with("\n") { + if data.as_slice().ends_with("\n") { // removes blank line that is inserted otherwise let mut buf = data.into_strbuf(); let len = buf.len(); buf.truncate(len - 1); data = buf.into_owned(); } - let split_vec: Vec<&str> = data.split_str(separator).collect(); - let rev: ~str = split_vec.iter().rev().fold("".to_owned(), |a, &b| - a + if before { - separator + b + let split_vec: Vec<&str> = data.as_slice().split_str(separator).collect(); + let rev: StrBuf = split_vec.iter().rev().fold(StrBuf::new(), |mut a, &b| { + if before { + a.push_str(separator); + a.push_str(b); } else { - b + separator + a.push_str(b); + a.push_str(separator); } - ); + a + }); print!("{}", rev); } } diff --git a/tee/tee.rs b/tee/tee.rs index 731fbe26b..08174dc2a 100644 --- a/tee/tee.rs +++ b/tee/tee.rs @@ -32,14 +32,14 @@ fn main() { } struct Options { - program: ~str, + program: StrBuf, append: bool, ignore_interrupts: bool, - print_and_exit: Option<~str>, + print_and_exit: Option, files: Box> } -fn options(args: &[~str]) -> Result { +fn options(args: &[StrBuf]) -> Result { let opts = ~[ optflag("a", "append", "append to the given FILEs, do not overwrite"), optflag("i", "ignore-interrupts", "ignore interrupt signals"), @@ -53,8 +53,7 @@ fn options(args: &[~str]) -> Result { let version = format!("{} {}", NAME, VERSION); let program = args.get(0).as_slice(); let arguments = "[OPTION]... [FILE]..."; - let brief = "Copy standard input to each FILE, and also to standard " + - "output."; + let brief = "Copy standard input to each FILE, and also to standard output."; let comment = "If a FILE is -, copy again to standard output."; let help = format!("{}\n\nUsage:\n {} {}\n\n{}\n{}", version, program, arguments, usage(brief, opts), @@ -64,7 +63,7 @@ fn options(args: &[~str]) -> Result { else if m.opt_present("version") { Some(version) } else { None }; Ok(Options { - program: program.into_owned(), + program: program.to_strbuf(), append: m.opt_present("append"), ignore_interrupts: m.opt_present("ignore-interrupts"), print_and_exit: to_print, @@ -75,7 +74,7 @@ fn options(args: &[~str]) -> Result { fn exec(options: Options) -> Result<(), ()> { match options.print_and_exit { - Some(text) => Ok(println(text)), + Some(text) => Ok(println(text.as_slice())), None => tee(options) } } @@ -145,7 +144,7 @@ impl Reader for NamedReader { fn with_path(path: &Path, cb: || -> IoResult) -> IoResult { match cb() { - Err(f) => { warn(format!("{}: {}", path.display(), f.to_str())); Err(f) } + Err(f) => { warn(format!("{}: {}", path.display(), f.to_str()).as_slice()); Err(f) } okay => okay } } diff --git a/truncate/truncate.rs b/truncate/truncate.rs index 039af2fb8..26b9f449c 100644 --- a/truncate/truncate.rs +++ b/truncate/truncate.rs @@ -178,7 +178,7 @@ fn parse_size(size: &str) -> (u64, TruncateMode) { } slice }.to_owned().into_bytes(); - let mut number = match u64::parse_bytes(bytes, 10) { + let mut number = match u64::parse_bytes(bytes.as_slice(), 10) { Some(num) => num, None => { crash!(1, "'{}' is not a valid number.", size) diff --git a/tty/tty.rs b/tty/tty.rs index cd482fae1..a5502c101 100644 --- a/tty/tty.rs +++ b/tty/tty.rs @@ -55,8 +55,8 @@ fn main () { let tty = unsafe { str::raw::from_c_str(ttyname(libc::STDIN_FILENO)) }; if !silent { - if !tty.is_whitespace() { - println(tty); + if !tty.as_slice().is_whitespace() { + println(tty.as_slice()); } else { println!("not a tty"); } diff --git a/uname/uname.rs b/uname/uname.rs index 2b2fce57c..b9d90ac19 100644 --- a/uname/uname.rs +++ b/uname/uname.rs @@ -27,11 +27,11 @@ use c_types::utsname; #[path = "../common/c_types.rs"] mod c_types; struct utsrust { - sysname: ~str, - nodename: ~str, - release: ~str, - version: ~str, - machine: ~str + sysname: StrBuf, + nodename: StrBuf, + release: StrBuf, + version: StrBuf, + machine: StrBuf } extern { @@ -81,24 +81,24 @@ fn main() { let mut output = StrBuf::new(); if matches.opt_present("sysname") || matches.opt_present("all") || !matches.opts_present(["nodename".to_strbuf(), "release".to_strbuf(), "version".to_strbuf(), "machine".to_strbuf()]) { - output.push_str(uname.sysname); + output.push_str(uname.sysname.as_slice()); output.push_str(" "); } if matches.opt_present("nodename") || matches.opt_present("all") { - output.push_str(uname.nodename); + output.push_str(uname.nodename.as_slice()); output.push_str(" "); } if matches.opt_present("release") || matches.opt_present("all") { - output.push_str(uname.release); + output.push_str(uname.release.as_slice()); output.push_str(" "); } if matches.opt_present("version") || matches.opt_present("all") { - output.push_str(uname.version); + output.push_str(uname.version.as_slice()); output.push_str(" "); } if matches.opt_present("machine") || matches.opt_present("all") { - output.push_str(uname.machine); + output.push_str(uname.machine.as_slice()); output.push_str(" "); } println!("{}", output.as_slice().trim_left()) diff --git a/uptime/uptime.rs b/uptime/uptime.rs index 21e5c4dbb..12650d24d 100644 --- a/uptime/uptime.rs +++ b/uptime/uptime.rs @@ -167,8 +167,8 @@ fn get_uptime(boot_time: Option) -> i64 { } }; - match uptime_text.words().next() { - Some(s) => match from_str(s.replace(".","")) { + match uptime_text.as_slice().words().next() { + Some(s) => match from_str(s.replace(".","").as_slice()) { Some(n) => n, None => -1 }, diff --git a/wc/wc.rs b/wc/wc.rs index ec3fb5598..53be97909 100644 --- a/wc/wc.rs +++ b/wc/wc.rs @@ -23,7 +23,7 @@ use getopts::Matches; mod util; struct Result { - filename: ~str, + filename: StrBuf, bytes: uint, chars: uint, lines: uint, @@ -155,7 +155,7 @@ pub fn wc(files: Vec, matches: &Matches) { } results.push(Result { - filename: path.as_slice().to_owned(), + filename: path.to_strbuf(), bytes: byte_count, chars: char_count, lines: line_count, @@ -177,15 +177,15 @@ pub fn wc(files: Vec, matches: &Matches) { } for result in results.iter() { - print_stats(&result.filename, result.lines, result.words, result.chars, result.bytes, result.max_line_length, matches, max_str_len); + print_stats(result.filename.as_slice(), result.lines, result.words, result.chars, result.bytes, result.max_line_length, matches, max_str_len); } if files.len() > 1 { - print_stats(&"total".to_owned(), total_line_count, total_word_count, total_char_count, total_byte_count, total_longest_line_length, matches, max_str_len); + print_stats("total", total_line_count, total_word_count, total_char_count, total_byte_count, total_longest_line_length, matches, max_str_len); } } -fn print_stats(filename: &~str, line_count: uint, word_count: uint, char_count: uint, +fn print_stats(filename: &str, line_count: uint, word_count: uint, char_count: uint, byte_count: uint, longest_line_length: uint, matches: &Matches, max_str_len: uint) { if matches.opt_present("lines") { print!("{:1$}", line_count, max_str_len); @@ -214,16 +214,16 @@ fn print_stats(filename: &~str, line_count: uint, word_count: uint, char_count: print!("{:1$}", byte_count, max_str_len + 1); } - if *filename != "-".to_owned() { - println!(" {}", *filename); + if filename != "-" { + println!(" {}", filename.as_slice()); } else { println!(""); } } -fn open(path: ~str) -> Option>> { - if "-" == path { +fn open(path: StrBuf) -> Option>> { + if "-" == path.as_slice() { let reader = box stdin() as Box; return Some(BufferedReader::new(reader)); } diff --git a/whoami/whoami.rs b/whoami/whoami.rs index 20794e78d..56e04b3b8 100644 --- a/whoami/whoami.rs +++ b/whoami/whoami.rs @@ -30,7 +30,7 @@ extern { pub fn geteuid() -> libc::c_int; } -unsafe fn getusername() -> ~str { +unsafe fn getusername() -> StrBuf { let passwd: *c_passwd = getpwuid(geteuid()); let pw_name: *libc::c_char = (*passwd).pw_name; diff --git a/yes/yes.rs b/yes/yes.rs index e88aec95a..004be59f0 100644 --- a/yes/yes.rs +++ b/yes/yes.rs @@ -55,10 +55,10 @@ fn main() { string = matches.free.connect(" "); } - exec(string); + exec(string.as_slice()); } -pub fn exec(string: ~str) { +pub fn exec(string: &str) { loop { println(string); }