1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

Adapt to removal of ~str from libstd.

This commit is contained in:
Michael Gehring 2014-05-23 14:28:40 +02:00
parent db9d8c046a
commit 0ce3f0f4e1
28 changed files with 159 additions and 157 deletions

View file

@ -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) {

View file

@ -24,8 +24,8 @@ static NAME: &'static str = "basename";
static VERSION: &'static str = "1.0.0";
fn main() {
let args: Vec<StrBuf> = 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();
}

View file

@ -103,7 +103,7 @@ pub fn exec(files: Vec<StrBuf>, 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<StrBuf>, 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<StrBuf>, number: NumberingMode, show_nonprint: bool, show
}
}
fn open(path: ~str) -> Option<Box<Reader>> {
fn open(path: &str) -> Option<Box<Reader>> {
if "-" == path {
return Some(box stdin_raw() as Box<Reader>);
}

View file

@ -32,7 +32,7 @@ static VERSION: &'static str = "1.0.0";
struct Options {
all: bool,
program_name: ~str,
program_name: StrBuf,
max_depth: Option<uint>,
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))

View file

@ -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());
}
}

16
env/env.rs vendored
View file

@ -16,9 +16,9 @@
struct options {
ignore_env: bool,
null: bool,
unsets: Vec<~str>,
sets: Vec<(~str, ~str)>,
program: Vec<~str>
unsets: Vec<StrBuf>,
sets: Vec<(StrBuf, StrBuf)>,
program: Vec<StrBuf>
}
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();

View file

@ -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<StrBuf>, Option<StrBuf>) {
let mut args = Vec::<StrBuf>::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<StrBuf>, 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<Reader>
} else {
box safe_unwrap!(File::open(&Path::new(filename))) as Box<Reader>
@ -117,7 +117,7 @@ fn fold_file<T: io::Reader>(file: BufferedReader<T>, 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<T: io::Reader>(file: BufferedReader<T>, 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)

View file

@ -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<uint>) {
let mut options: Vec<~str> = options.move_iter().collect();
fn obsolete (options: &[StrBuf]) -> (Vec<StrBuf>, Option<uint>) {
let mut options: Vec<StrBuf> = 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<uint>) {
if pos == len - 1 {
options.remove(a);
let number : Option<uint> = 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<uint>) {
a += 1;
};
(options.as_slice().to_owned(), None)
(options, None)
}
fn head<T: Reader> (reader: &mut BufferedReader<T>, line_count:uint) {

View file

@ -52,7 +52,7 @@ extern {
fn main() {
let args: Vec<StrBuf> = 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) {

View file

@ -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<libc::c_char> = 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);
}
}

View file

@ -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<StrBuf>) {
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<uint> {
if signal_name_or_value == "0".to_owned() {
fn signal_by_name_or_value(signal_name_or_value: &str) -> Option<uint> {
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<uint> {
}
fn kill(signalname: &str, pids: std::vec::Vec<StrBuf>) {
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)

View file

@ -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() {

View file

@ -84,7 +84,7 @@ fn md5sum(files: Vec<StrBuf>, 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<Reader>
} else {
box safe_unwrap!(File::open(&Path::new(filename))) as Box<Reader>
@ -95,9 +95,9 @@ fn md5sum(files: Vec<StrBuf>, 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<StrBuf>, 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<StrBuf>, 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()
}

View file

@ -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));
}
/**

View file

@ -66,23 +66,26 @@ fn paste(filenames: Vec<StrBuf>, serial: bool, delimiters: &str) {
}
)
).collect();
let delimiters: Vec<~str> = delimiters.chars().map(|x| x.to_str()).collect();
let delimiters: Vec<StrBuf> = 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<StrBuf>, 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<StrBuf>, 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;
}
}

View file

@ -72,7 +72,7 @@ pub fn exec(args: Vec<StrBuf>, 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);
}
_ => ()

View file

@ -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,
_ => {

View file

@ -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<f32, ~str>{
fn parse_float(s: &str) -> Result<f32, StrBuf>{
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) {

View file

@ -67,17 +67,17 @@ fn sleep(args: Vec<StrBuf>) {
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::<f64>((arg), 10) {
match num::from_str_radix::<f64>((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<StrBuf>) {
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))
}

View file

@ -79,21 +79,24 @@ fn tac(filenames: Vec<StrBuf>, 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);
}
}

View file

@ -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<StrBuf>,
files: Box<Vec<Path>>
}
fn options(args: &[~str]) -> Result<Options, ()> {
fn options(args: &[StrBuf]) -> Result<Options, ()> {
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<Options, ()> {
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<Options, ()> {
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<Options, ()> {
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<T>(path: &Path, cb: || -> IoResult<T>) -> IoResult<T> {
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
}
}

View file

@ -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)

View file

@ -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");
}

View file

@ -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())

View file

@ -167,8 +167,8 @@ fn get_uptime(boot_time: Option<time_t>) -> 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
},

View file

@ -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<StrBuf>, 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<StrBuf>, 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<BufferedReader<Box<Reader>>> {
if "-" == path {
fn open(path: StrBuf) -> Option<BufferedReader<Box<Reader>>> {
if "-" == path.as_slice() {
let reader = box stdin() as Box<Reader>;
return Some(BufferedReader::new(reader));
}

View file

@ -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;

View file

@ -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);
}