mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
to_{strbuf,owned} -> to_string
This commit is contained in:
parent
005876ac53
commit
9b3bfed359
22 changed files with 63 additions and 63 deletions
|
@ -100,12 +100,12 @@ fn strip_dir(fullname: &str) -> String {
|
|||
|
||||
fn strip_suffix(name: &str, suffix: &str) -> String {
|
||||
if name == suffix {
|
||||
return name.into_strbuf();
|
||||
return name.into_string();
|
||||
}
|
||||
|
||||
if name.ends_with(suffix) {
|
||||
return name.slice_to(name.len() - suffix.len()).into_strbuf();
|
||||
return name.slice_to(name.len() - suffix.len()).into_string();
|
||||
}
|
||||
|
||||
return name.into_strbuf();
|
||||
return name.into_string();
|
||||
}
|
||||
|
|
|
@ -62,13 +62,13 @@ fn main() {
|
|||
if matches.opt_present("number-nonblank") {
|
||||
number_mode = NumberNonEmpty;
|
||||
}
|
||||
let show_nonprint = matches.opts_present(["show-nonprinting".to_strbuf(), "show-all".to_strbuf(), "t".to_strbuf(), "e".to_strbuf()]);
|
||||
let show_ends = matches.opts_present(["show-ends".to_strbuf(), "show-all".to_strbuf(), "e".to_strbuf()]);
|
||||
let show_tabs = matches.opts_present(["show-tabs".to_strbuf(), "show-all".to_strbuf(), "t".to_strbuf()]);
|
||||
let show_nonprint = matches.opts_present(["show-nonprinting".to_string(), "show-all".to_string(), "t".to_string(), "e".to_string()]);
|
||||
let show_ends = matches.opts_present(["show-ends".to_string(), "show-all".to_string(), "e".to_string()]);
|
||||
let show_tabs = matches.opts_present(["show-tabs".to_string(), "show-all".to_string(), "t".to_string()]);
|
||||
let squeeze_blank = matches.opt_present("squeeze-blank");
|
||||
let mut files = matches.free;
|
||||
if files.is_empty() {
|
||||
files = vec!("-".to_strbuf());
|
||||
files = vec!("-".to_string());
|
||||
}
|
||||
|
||||
exec(files, number_mode, show_nonprint, show_ends, show_tabs, squeeze_blank);
|
||||
|
|
|
@ -25,7 +25,7 @@ fn mkdelim(col: uint, opts: &getopts::Matches) -> String {
|
|||
let mut s = String::new();
|
||||
let delim = match opts.opt_str("output-delimiter") {
|
||||
Some(d) => d.clone(),
|
||||
None => "\t".to_strbuf(),
|
||||
None => "\t".to_string(),
|
||||
};
|
||||
|
||||
if col > 1 && !opts.opt_present("1") {
|
||||
|
|
4
du/du.rs
4
du/du.rs
|
@ -210,13 +210,13 @@ ers of 1000).",
|
|||
|
||||
let options = Options {
|
||||
all: matches.opt_present("all"),
|
||||
program_name: program.to_owned(),
|
||||
program_name: program.to_string(),
|
||||
max_depth: max_depth,
|
||||
total: matches.opt_present("total"),
|
||||
separate_dirs: matches.opt_present("S"),
|
||||
};
|
||||
|
||||
let strs = if matches.free.is_empty() {vec!("./".to_strbuf())} else {matches.free.clone()};
|
||||
let strs = if matches.free.is_empty() {vec!("./".to_string())} else {matches.free.clone()};
|
||||
|
||||
let options_arc = Arc::new(options);
|
||||
|
||||
|
|
10
env/env.rs
vendored
10
env/env.rs
vendored
|
@ -87,7 +87,7 @@ fn main() {
|
|||
}
|
||||
_ => {
|
||||
// read the program now
|
||||
opts.program.push(opt.to_owned());
|
||||
opts.program.push(opt.to_string());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ fn main() {
|
|||
|
||||
match var {
|
||||
None => println!("{:s}: this option requires an argument: {:s}", prog, opt.as_slice()),
|
||||
Some(s) => opts.unsets.push(s.to_owned())
|
||||
Some(s) => opts.unsets.push(s.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ fn main() {
|
|||
|
||||
match var {
|
||||
None => println!("{:s}: this option requires an argument: {:s}", prog, opt.as_slice()),
|
||||
Some(s) => opts.unsets.push(s.to_owned())
|
||||
Some(s) => opts.unsets.push(s.to_string())
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
|
@ -160,7 +160,7 @@ fn main() {
|
|||
}
|
||||
// no, its a program-like opt
|
||||
_ => {
|
||||
opts.program.push(opt.to_owned());
|
||||
opts.program.push(opt.to_string());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ fn main() {
|
|||
|
||||
// read program arguments
|
||||
for opt in iter {
|
||||
opts.program.push(opt.to_owned());
|
||||
opts.program.push(opt.to_string());
|
||||
}
|
||||
|
||||
let env = std::os::env();
|
||||
|
|
14
fold/fold.rs
14
fold/fold.rs
|
@ -62,7 +62,7 @@ fn main() {
|
|||
matches.opt_str("w")
|
||||
} else {
|
||||
match obs_width {
|
||||
Some(v) => Some(v.to_strbuf()),
|
||||
Some(v) => Some(v.to_string()),
|
||||
None => None,
|
||||
}
|
||||
};
|
||||
|
@ -74,7 +74,7 @@ fn main() {
|
|||
None => 80
|
||||
};
|
||||
let files = if matches.free.is_empty() {
|
||||
vec!("-".to_strbuf())
|
||||
vec!("-".to_string())
|
||||
} else {
|
||||
matches.free
|
||||
};
|
||||
|
@ -88,7 +88,7 @@ fn handle_obsolete(args: &[String]) -> (Vec<String>, Option<String>) {
|
|||
while i < args.len() {
|
||||
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()));
|
||||
Some(args.remove(i).unwrap().as_slice().slice_from(1).to_string()));
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
|
@ -172,19 +172,19 @@ fn fold_file<T: io::Reader>(file: BufferedReader<T>, bytes: bool, spaces: bool,
|
|||
if spaces && i + 1 != line.len() {
|
||||
match slice.rfind(|ch: char| ch.is_whitespace()) {
|
||||
Some(m) => {
|
||||
let routput = slice.slice_from(m + 1).to_owned();
|
||||
let routput = slice.slice_from(m + 1).to_string();
|
||||
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)
|
||||
None => (slice, "".to_string(), 0)
|
||||
}
|
||||
} else {
|
||||
(slice, "".to_owned(), 0)
|
||||
(slice, "".to_string(), 0)
|
||||
};
|
||||
println!("{}", out);
|
||||
(val, ncount)
|
||||
};
|
||||
output = val.into_strbuf();
|
||||
output = val.into_string();
|
||||
count = ncount;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ fn xgethostname() -> String {
|
|||
|
||||
let last_char = name.iter().position(|byte| *byte == 0).unwrap_or(namelen);
|
||||
|
||||
str::from_utf8(name.slice_to(last_char)).unwrap().to_owned()
|
||||
str::from_utf8(name.slice_to(last_char)).unwrap().to_string()
|
||||
}
|
||||
|
||||
fn xsethostname(name: &str) {
|
||||
|
|
|
@ -89,7 +89,7 @@ fn main() {
|
|||
};
|
||||
|
||||
match mode {
|
||||
Kill => kill(matches.opt_str("signal").unwrap_or("9".to_strbuf()).as_slice(), matches.free),
|
||||
Kill => kill(matches.opt_str("signal").unwrap_or("9".to_string()).as_slice(), matches.free),
|
||||
Table => table(),
|
||||
List => list(matches.opt_str("list")),
|
||||
Help => help(NAME, usage.as_slice()),
|
||||
|
|
|
@ -68,7 +68,7 @@ fn main() {
|
|||
let strict = matches.opt_present("strict");
|
||||
let warn = matches.opt_present("warn") && !status;
|
||||
let files = if matches.free.is_empty() {
|
||||
vec!("-".to_strbuf())
|
||||
vec!("-".to_string())
|
||||
} else {
|
||||
matches.free
|
||||
};
|
||||
|
|
|
@ -63,7 +63,7 @@ fn main() {
|
|||
|
||||
// Translate a ~str in octal form to u32, default to 755
|
||||
// Not tested on Windows
|
||||
let mode_match = matches.opts_str(&["mode".to_strbuf()]);
|
||||
let mode_match = matches.opts_str(&["mode".to_string()]);
|
||||
let mode: FilePermission = if mode_match.is_some() {
|
||||
let m = mode_match.unwrap();
|
||||
let res: Option<u32> = strconv::from_str_common(m.as_slice(), 8, false, false, false,
|
||||
|
@ -105,7 +105,7 @@ fn exec(dirs: Vec<String>, mk_parents: bool, mode: FilePermission, verbose: bool
|
|||
match parent {
|
||||
Some(p) => {
|
||||
if !Path::new(p).exists() {
|
||||
parent_dirs.push(p.to_strbuf())
|
||||
parent_dirs.push(p.to_string())
|
||||
}
|
||||
},
|
||||
None => ()
|
||||
|
|
|
@ -50,7 +50,7 @@ fn main() {
|
|||
let serial = matches.opt_present("serial");
|
||||
let delimiters = match matches.opt_str("delimiters") {
|
||||
Some(m) => m,
|
||||
None => "\t".to_strbuf()
|
||||
None => "\t".to_string()
|
||||
};
|
||||
paste(matches.free, serial, delimiters.as_slice());
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ fn paste(filenames: Vec<String>, serial: bool, delimiters: &str) {
|
|||
} else {
|
||||
let mut eof = Vec::from_elem(files.len(), false);
|
||||
loop {
|
||||
let mut output = "".to_owned();
|
||||
let mut output = "".to_string();
|
||||
let mut eof_count = 0;
|
||||
for (i, file) in files.mut_iter().enumerate() {
|
||||
if *eof.get(i) {
|
||||
|
|
2
rm/rm.rs
2
rm/rm.rs
|
@ -133,7 +133,7 @@ fn remove(files: Vec<String>, force: bool, interactive: InteractiveMode, one_fs:
|
|||
crash!(1, "{}", f.to_str());
|
||||
}
|
||||
};
|
||||
remove(walk_dir.map(|x| x.as_str().unwrap().to_strbuf()).collect(), force, interactive, one_fs, preserve_root, recursive, dir, verbose);
|
||||
remove(walk_dir.map(|x| x.as_str().unwrap().to_string()).collect(), force, interactive, one_fs, preserve_root, recursive, dir, verbose);
|
||||
remove_dir(&file, filename, interactive, verbose);
|
||||
} else if dir && (filename != "/" || !preserve_root) {
|
||||
remove_dir(&file, filename, interactive, verbose);
|
||||
|
|
|
@ -83,8 +83,8 @@ fn main() {
|
|||
Ok(n) => n,
|
||||
Err(s) => { show_error!(1, "{:s}", s); return; }
|
||||
};
|
||||
let separator = escape_sequences(matches.opt_str("s").unwrap_or("\n".to_strbuf()).as_slice());
|
||||
let terminator = escape_sequences(matches.opt_str("t").unwrap_or(separator.to_strbuf()).as_slice());
|
||||
let separator = escape_sequences(matches.opt_str("s").unwrap_or("\n".to_string()).as_slice());
|
||||
let terminator = escape_sequences(matches.opt_str("t").unwrap_or(separator.to_string()).as_slice());
|
||||
print_seq(first, step, last, separator, terminator, matches.opt_present("w"));
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ fn sleep(args: Vec<String>) {
|
|||
let (arg, suffix_time) = match match_suffix(arg.as_slice()) {
|
||||
Ok(m) => m,
|
||||
Err(f) => {
|
||||
crash!(1, "{}", f.to_strbuf())
|
||||
crash!(1, "{}", f.to_string())
|
||||
}
|
||||
};
|
||||
let num =
|
||||
|
@ -77,7 +77,7 @@ fn sleep(args: Vec<String>) {
|
|||
match num::from_str_radix::<f64>((arg.as_slice()), 10) {
|
||||
Some(m) => m,
|
||||
None => {
|
||||
crash!(1, "Invalid time interval '{}'", arg.to_strbuf())
|
||||
crash!(1, "Invalid time interval '{}'", arg.to_string())
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -94,11 +94,11 @@ fn match_suffix(arg: &str) -> Result<(String, int), String> {
|
|||
'd' | 'D' => 60 * 60 * 24,
|
||||
val => {
|
||||
if !val.is_alphabetic() {
|
||||
return Ok((arg.to_strbuf(), 1))
|
||||
return Ok((arg.to_string(), 1))
|
||||
} else {
|
||||
return Err(format!("Invalid time interval '{}'", arg))
|
||||
}
|
||||
}
|
||||
};
|
||||
Ok(((arg).slice_to((arg).len() - 1).to_owned(), result))
|
||||
Ok(((arg).slice_to((arg).len() - 1).to_string(), result))
|
||||
}
|
||||
|
|
|
@ -58,10 +58,10 @@ fn main() {
|
|||
m
|
||||
}
|
||||
}
|
||||
None => "\n".to_strbuf()
|
||||
None => "\n".to_string()
|
||||
};
|
||||
let files = if matches.free.is_empty() {
|
||||
vec!("-".to_strbuf())
|
||||
vec!("-".to_string())
|
||||
} else {
|
||||
matches.free
|
||||
};
|
||||
|
@ -81,7 +81,7 @@ fn tac(filenames: Vec<String>, before: bool, _: bool, separator: &str) {
|
|||
let mut data = crash_if_err!(1, file.read_to_str());
|
||||
if data.as_slice().ends_with("\n") {
|
||||
// removes blank line that is inserted otherwise
|
||||
let mut buf = data.into_strbuf();
|
||||
let mut buf = data.into_string();
|
||||
let len = buf.len();
|
||||
buf.truncate(len - 1);
|
||||
data = buf.into_owned();
|
||||
|
|
|
@ -47,7 +47,7 @@ fn options(args: &[String]) -> Result<Options, ()> {
|
|||
optflag("V", "version", "output version information and exit"),
|
||||
];
|
||||
|
||||
let args: Vec<String> = args.iter().map(|x| x.to_strbuf()).collect();
|
||||
let args: Vec<String> = args.iter().map(|x| x.to_string()).collect();
|
||||
|
||||
getopts(args.tail(), opts).map_err(|e| e.to_err_msg()).and_then(|m| {
|
||||
let version = format!("{} {}", NAME, VERSION);
|
||||
|
@ -58,12 +58,12 @@ fn options(args: &[String]) -> Result<Options, ()> {
|
|||
let help = format!("{}\n\nUsage:\n {} {}\n\n{}\n{}",
|
||||
version, program, arguments, usage(brief, opts),
|
||||
comment);
|
||||
let names = m.free.clone().move_iter().collect::<Vec<String>>().append_one("-".to_strbuf());
|
||||
let names = m.free.clone().move_iter().collect::<Vec<String>>().append_one("-".to_string());
|
||||
let to_print = if m.opt_present("help") { Some(help) }
|
||||
else if m.opt_present("version") { Some(version) }
|
||||
else { None };
|
||||
Ok(Options {
|
||||
program: program.to_strbuf(),
|
||||
program: program.to_string(),
|
||||
append: m.opt_present("append"),
|
||||
ignore_interrupts: m.opt_present("ignore-interrupts"),
|
||||
print_and_exit: to_print,
|
||||
|
|
|
@ -60,18 +60,18 @@ fn main() {
|
|||
return;
|
||||
}
|
||||
|
||||
if matches.opt_present("date") && matches.opts_present(["reference".to_owned(), "t".to_owned()]) ||
|
||||
matches.opt_present("reference") && matches.opts_present(["date".to_owned(), "t".to_owned()]) ||
|
||||
matches.opt_present("t") && matches.opts_present(["date".to_owned(), "reference".to_owned()]) {
|
||||
if matches.opt_present("date") && matches.opts_present(["reference".to_string(), "t".to_string()]) ||
|
||||
matches.opt_present("reference") && matches.opts_present(["date".to_string(), "t".to_string()]) ||
|
||||
matches.opt_present("t") && matches.opts_present(["date".to_string(), "reference".to_string()]) {
|
||||
fail!("Invalid options: cannot specify reference time from more than one source");
|
||||
}
|
||||
|
||||
let (mut atime, mut mtime) =
|
||||
if matches.opt_present("reference") {
|
||||
let path = Path::new(matches.opt_str("reference").unwrap().to_owned());
|
||||
let path = Path::new(matches.opt_str("reference").unwrap().to_string());
|
||||
let stat = stat(&path, !matches.opt_present("no-dereference"));
|
||||
(stat.accessed, stat.modified)
|
||||
} else if matches.opts_present(["date".to_owned(), "t".to_owned()]) {
|
||||
} else if matches.opts_present(["date".to_string(), "t".to_string()]) {
|
||||
let timestamp = if matches.opt_present("date") {
|
||||
parse_date(matches.opt_str("date").unwrap().as_slice())
|
||||
} else {
|
||||
|
@ -85,11 +85,11 @@ fn main() {
|
|||
};
|
||||
|
||||
for filename in matches.free.iter() {
|
||||
let path = Path::new(filename.to_owned());
|
||||
let path = Path::new(filename.to_string());
|
||||
|
||||
if !path.exists() {
|
||||
// no-dereference included here for compatibility
|
||||
if matches.opts_present(["no-create".to_owned(), "no-dereference".to_owned()]) {
|
||||
if matches.opts_present(["no-create".to_string(), "no-dereference".to_string()]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -99,27 +99,27 @@ fn main() {
|
|||
};
|
||||
|
||||
// Minor optimization: if no reference time was specified, we're done.
|
||||
if !matches.opts_present(["date".to_owned(), "reference".to_owned(), "t".to_owned()]) {
|
||||
if !matches.opts_present(["date".to_string(), "reference".to_string(), "t".to_string()]) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// If changing "only" atime or mtime, grab the existing value of the other.
|
||||
// Note that "-a" and "-m" may be passed together; this is not an xor.
|
||||
if matches.opts_present(["a".to_owned(), "m".to_owned(), "time".to_owned()]) {
|
||||
if matches.opts_present(["a".to_string(), "m".to_string(), "time".to_string()]) {
|
||||
let stat = stat(&path, !matches.opt_present("no-dereference"));
|
||||
let time = matches.opt_strs("time");
|
||||
|
||||
if !(matches.opt_present("a") ||
|
||||
time.contains(&"access".to_strbuf()) ||
|
||||
time.contains(&"atime".to_strbuf()) ||
|
||||
time.contains(&"use".to_strbuf())) {
|
||||
time.contains(&"access".to_string()) ||
|
||||
time.contains(&"atime".to_string()) ||
|
||||
time.contains(&"use".to_string())) {
|
||||
atime = stat.accessed;
|
||||
}
|
||||
|
||||
if !(matches.opt_present("m") ||
|
||||
time.contains(&"modify".to_strbuf()) ||
|
||||
time.contains(&"mtime".to_strbuf())) {
|
||||
time.contains(&"modify".to_string()) ||
|
||||
time.contains(&"mtime".to_string())) {
|
||||
mtime = stat.modified;
|
||||
}
|
||||
}
|
||||
|
|
2
tr/tr.rs
2
tr/tr.rs
|
@ -181,7 +181,7 @@ pub fn main() {
|
|||
}
|
||||
|
||||
let dflag = matches.opt_present("d");
|
||||
let cflag = matches.opts_present(["c".to_strbuf(), "C".to_strbuf()]);
|
||||
let cflag = matches.opts_present(["c".to_string(), "C".to_string()]);
|
||||
let sets = matches.free;
|
||||
|
||||
if cflag && !dflag {
|
||||
|
|
|
@ -177,7 +177,7 @@ fn parse_size(size: &str) -> (u64, TruncateMode) {
|
|||
}
|
||||
}
|
||||
slice
|
||||
}.to_owned().into_bytes();
|
||||
}.to_string().into_bytes();
|
||||
let mut number = match u64::parse_bytes(bytes.as_slice(), 10) {
|
||||
Some(num) => num,
|
||||
None => {
|
||||
|
|
|
@ -80,7 +80,7 @@ fn main() {
|
|||
let uname = unsafe { getuname() };
|
||||
let mut output = String::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()]) {
|
||||
|| !matches.opts_present(["nodename".to_string(), "release".to_string(), "version".to_string(), "machine".to_string()]) {
|
||||
output.push_str(uname.sysname.as_slice());
|
||||
output.push_str(" ");
|
||||
}
|
||||
|
|
6
wc/wc.rs
6
wc/wc.rs
|
@ -70,7 +70,7 @@ fn main() {
|
|||
|
||||
let mut files = matches.free.clone();
|
||||
if files.is_empty() {
|
||||
files = vec!("-".to_strbuf());
|
||||
files = vec!("-".to_string());
|
||||
}
|
||||
|
||||
wc(files, &matches);
|
||||
|
@ -98,7 +98,7 @@ pub fn wc(files: Vec<String>, matches: &Matches) {
|
|||
let mut max_str_len: uint = 0;
|
||||
|
||||
for path in files.iter() {
|
||||
let mut reader = match open(path.to_owned()) {
|
||||
let mut reader = match open(path.to_string()) {
|
||||
Some(f) => f,
|
||||
None => { continue }
|
||||
};
|
||||
|
@ -155,7 +155,7 @@ pub fn wc(files: Vec<String>, matches: &Matches) {
|
|||
}
|
||||
|
||||
results.push(Result {
|
||||
filename: path.to_strbuf(),
|
||||
filename: path.to_string(),
|
||||
bytes: byte_count,
|
||||
chars: char_count,
|
||||
lines: line_count,
|
||||
|
|
|
@ -50,7 +50,7 @@ fn main() {
|
|||
println!("yes 1.0.0");
|
||||
return;
|
||||
}
|
||||
let mut string = "y".to_owned();
|
||||
let mut string = "y".to_string();
|
||||
if !matches.free.is_empty() {
|
||||
string = matches.free.connect(" ");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue