mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-01 13:37:48 +00:00
str::from_str removal/changes
This commit is contained in:
parent
7d8053561e
commit
fd69e7fa4a
10 changed files with 24 additions and 25 deletions
|
@ -23,19 +23,19 @@ impl std::str::FromStr for Range {
|
||||||
|
|
||||||
match (parts.next(), parts.next()) {
|
match (parts.next(), parts.next()) {
|
||||||
(Some(nm), None) => {
|
(Some(nm), None) => {
|
||||||
from_str::<uint>(nm).and_then(|nm| if nm > 0 { Some(nm) } else { None })
|
std::str::FromStr::from_str::<uint>(nm).and_then(|nm| if nm > 0 { Some(nm) } else { None })
|
||||||
.map(|nm| Range { low: nm, high: nm })
|
.map(|nm| Range { low: nm, high: nm })
|
||||||
}
|
}
|
||||||
(Some(n), Some(m)) if m.len() == 0 => {
|
(Some(n), Some(m)) if m.len() == 0 => {
|
||||||
from_str::<uint>(n).and_then(|low| if low > 0 { Some(low) } else { None })
|
std::str::FromStr::from_str::<uint>(n).and_then(|low| if low > 0 { Some(low) } else { None })
|
||||||
.map(|low| Range { low: low, high: MAX })
|
.map(|low| Range { low: low, high: MAX })
|
||||||
}
|
}
|
||||||
(Some(n), Some(m)) if n.len() == 0 => {
|
(Some(n), Some(m)) if n.len() == 0 => {
|
||||||
from_str::<uint>(m).and_then(|high| if high >= 1 { Some(high) } else { None })
|
std::str::FromStr::from_str::<uint>(m).and_then(|high| if high >= 1 { Some(high) } else { None })
|
||||||
.map(|high| Range { low: 1, high: high })
|
.map(|high| Range { low: 1, high: high })
|
||||||
}
|
}
|
||||||
(Some(n), Some(m)) => {
|
(Some(n), Some(m)) => {
|
||||||
match (from_str::<uint>(n), from_str::<uint>(m)) {
|
match (std::str::FromStr::from_str::<uint>(n), std::str::FromStr::from_str::<uint>(m)) {
|
||||||
(Some(low), Some(high)) if low > 0 && low <= high => {
|
(Some(low), Some(high)) if low > 0 && low <= high => {
|
||||||
Some(Range { low: low, high: high })
|
Some(Range { low: low, high: high })
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ impl Range {
|
||||||
let mut ranges = vec!();
|
let mut ranges = vec!();
|
||||||
|
|
||||||
for item in list.split(',') {
|
for item in list.split(',') {
|
||||||
match from_str::<Range>(item) {
|
match std::str::FromStr::from_str(item) {
|
||||||
Some(range_item) => ranges.push(range_item),
|
Some(range_item) => ranges.push(range_item),
|
||||||
None => return Err(format!("range '{}' was invalid", item))
|
None => return Err(format!("range '{}' was invalid", item))
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::str::from_str;
|
use std::str::StrExt;
|
||||||
|
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -28,7 +28,7 @@ fn tabstops_parse(s: String) -> Vec<uint> {
|
||||||
let words = s.as_slice().split(',').collect::<Vec<&str>>();
|
let words = s.as_slice().split(',').collect::<Vec<&str>>();
|
||||||
|
|
||||||
let nums = words.into_iter()
|
let nums = words.into_iter()
|
||||||
.map(|sn| from_str::<uint>(sn)
|
.map(|sn| sn.parse::<uint>()
|
||||||
.unwrap_or_else(
|
.unwrap_or_else(
|
||||||
|| crash!(1, "{}\n", "tab size contains invalid character(s)"))
|
|| crash!(1, "{}\n", "tab size contains invalid character(s)"))
|
||||||
)
|
)
|
||||||
|
|
|
@ -56,7 +56,7 @@ fn print_factors(num: u64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_factors_str(num_str: &str) {
|
fn print_factors_str(num_str: &str) {
|
||||||
let num = match from_str(num_str) {
|
let num = match num_str.parse::<u64>() {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
None => { crash!(1, "{} not a number", num_str); }
|
None => { crash!(1, "{} not a number", num_str); }
|
||||||
};
|
};
|
||||||
|
|
|
@ -140,7 +140,7 @@ pub fn uumain(args: Vec<String>) -> int {
|
||||||
match matches.opt_str("w") {
|
match matches.opt_str("w") {
|
||||||
Some(s) => {
|
Some(s) => {
|
||||||
fmt_opts.width =
|
fmt_opts.width =
|
||||||
match from_str(s.as_slice()) {
|
match s.parse::<uint>() {
|
||||||
Some(t) => t,
|
Some(t) => t,
|
||||||
None => { crash!(1, "Invalid WIDTH specification: `{}'", s); }
|
None => { crash!(1, "Invalid WIDTH specification: `{}'", s); }
|
||||||
};
|
};
|
||||||
|
@ -152,7 +152,7 @@ pub fn uumain(args: Vec<String>) -> int {
|
||||||
match matches.opt_str("g") {
|
match matches.opt_str("g") {
|
||||||
Some(s) => {
|
Some(s) => {
|
||||||
fmt_opts.goal =
|
fmt_opts.goal =
|
||||||
match from_str(s.as_slice()) {
|
match s.parse::<uint>() {
|
||||||
Some(t) => t,
|
Some(t) => t,
|
||||||
None => { crash!(1, "Invalid GOAL specification: `{}'", s); }
|
None => { crash!(1, "Invalid GOAL specification: `{}'", s); }
|
||||||
};
|
};
|
||||||
|
@ -168,7 +168,7 @@ pub fn uumain(args: Vec<String>) -> int {
|
||||||
match matches.opt_str("T") {
|
match matches.opt_str("T") {
|
||||||
Some(s) => {
|
Some(s) => {
|
||||||
fmt_opts.tabwidth =
|
fmt_opts.tabwidth =
|
||||||
match from_str(s.as_slice()) {
|
match s.parse::<uint>() {
|
||||||
Some(t) => t,
|
Some(t) => t,
|
||||||
None => { crash!(1, "Invalid TABWIDTH specification: `{}'", s); }
|
None => { crash!(1, "Invalid TABWIDTH specification: `{}'", s); }
|
||||||
};
|
};
|
||||||
|
|
|
@ -62,7 +62,7 @@ pub fn uumain(args: Vec<String>) -> int {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let width = match poss_width {
|
let width = match poss_width {
|
||||||
Some(inp_width) => match from_str(inp_width.as_slice()) {
|
Some(inp_width) => match inp_width.parse::<uint>() {
|
||||||
Some(width) => width,
|
Some(width) => width,
|
||||||
None => crash!(1, "illegal width value (\"{}\")", inp_width)
|
None => crash!(1, "illegal width value (\"{}\")", inp_width)
|
||||||
},
|
},
|
||||||
|
|
|
@ -68,7 +68,7 @@ pub fn uumain(args: Vec<String>) -> int {
|
||||||
show_error!("cannot specify both --bytes and --lines.");
|
show_error!("cannot specify both --bytes and --lines.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
match from_str(n.as_slice()) {
|
match n.parse::<uint>() {
|
||||||
Some(m) => { line_count = m }
|
Some(m) => { line_count = m }
|
||||||
None => {
|
None => {
|
||||||
show_error!("invalid line count '{}'", n);
|
show_error!("invalid line count '{}'", n);
|
||||||
|
@ -77,7 +77,7 @@ pub fn uumain(args: Vec<String>) -> int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => match given_options.opt_str("c") {
|
None => match given_options.opt_str("c") {
|
||||||
Some(count) => match from_str(count.as_slice()) {
|
Some(count) => match count.parse::<uint>() {
|
||||||
Some(m) => byte_count = m,
|
Some(m) => byte_count = m,
|
||||||
None => {
|
None => {
|
||||||
show_error!("invalid byte count '{}'", count);
|
show_error!("invalid byte count '{}'", count);
|
||||||
|
@ -149,7 +149,7 @@ fn obsolete(options: &[String]) -> (Vec<String>, Option<uint>) {
|
||||||
// If this is the last number
|
// If this is the last number
|
||||||
if pos == len - 1 {
|
if pos == len - 1 {
|
||||||
options.remove(a);
|
options.remove(a);
|
||||||
let number: Option<uint> = from_str(from_utf8(current.slice(1,len)).unwrap());
|
let number: Option<uint> = from_utf8(current.slice(1,len)).unwrap().parse::<uint>();
|
||||||
return (options, Some(number.unwrap()));
|
return (options, Some(number.unwrap()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ pub fn uumain(args: Vec<String>) -> int {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut ignore = match matches.opt_str("ignore") {
|
let mut ignore = match matches.opt_str("ignore") {
|
||||||
Some(numstr) => match from_str(numstr.as_slice()) {
|
Some(numstr) => match numstr.parse() {
|
||||||
Some(num) => num,
|
Some(num) => num,
|
||||||
None => {
|
None => {
|
||||||
show_error!("\"{}\" is not a valid number", numstr);
|
show_error!("\"{}\" is not a valid number", numstr);
|
||||||
|
@ -64,7 +64,7 @@ pub fn uumain(args: Vec<String>) -> int {
|
||||||
|
|
||||||
if !matches.opt_present("all") {
|
if !matches.opt_present("all") {
|
||||||
ignore += match os::getenv("OMP_NUM_THREADS") {
|
ignore += match os::getenv("OMP_NUM_THREADS") {
|
||||||
Some(threadstr) => match from_str(threadstr.as_slice()) {
|
Some(threadstr) => match threadstr.parse() {
|
||||||
Some(num) => num,
|
Some(num) => num,
|
||||||
None => 0
|
None => 0
|
||||||
},
|
},
|
||||||
|
|
|
@ -13,7 +13,6 @@ extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::str::from_str;
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::IoResult;
|
use std::io::IoResult;
|
||||||
use std::iter::{range_inclusive, RangeInclusive};
|
use std::iter::{range_inclusive, RangeInclusive};
|
||||||
|
@ -96,7 +95,7 @@ With no FILE, or when FILE is -, read standard input.",
|
||||||
let repeat = matches.opt_present("repeat");
|
let repeat = matches.opt_present("repeat");
|
||||||
let zero = matches.opt_present("zero-terminated");
|
let zero = matches.opt_present("zero-terminated");
|
||||||
let count = match matches.opt_str("head-count") {
|
let count = match matches.opt_str("head-count") {
|
||||||
Some(cnt) => match from_str::<uint>(cnt.as_slice()) {
|
Some(cnt) => match cnt.parse::<uint>() {
|
||||||
Some(val) => val,
|
Some(val) => val,
|
||||||
None => {
|
None => {
|
||||||
show_error!("'{}' is not a valid count", cnt);
|
show_error!("'{}' is not a valid count", cnt);
|
||||||
|
@ -191,11 +190,11 @@ fn parse_range(input_range: String) -> Result<RangeInclusive<uint>, (String, int
|
||||||
if split.len() != 2 {
|
if split.len() != 2 {
|
||||||
Err(("invalid range format".to_string(), 1))
|
Err(("invalid range format".to_string(), 1))
|
||||||
} else {
|
} else {
|
||||||
let begin = match from_str::<uint>(split[0]) {
|
let begin = match split[0].parse::<uint>() {
|
||||||
Some(m) => m,
|
Some(m) => m,
|
||||||
None => return Err((format!("{} is not a valid number", split[0]), 1))
|
None => return Err((format!("{} is not a valid number", split[0]), 1))
|
||||||
};
|
};
|
||||||
let end = match from_str::<uint>(split[1]) {
|
let end = match split[1].parse::<uint>() {
|
||||||
Some(m) => m,
|
Some(m) => m,
|
||||||
None => return Err((format!("{} is not a valid number", split[1]), 1))
|
None => return Err((format!("{} is not a valid number", split[1]), 1))
|
||||||
};
|
};
|
||||||
|
|
|
@ -71,7 +71,7 @@ pub fn uumain(args: Vec<String>) -> int {
|
||||||
if follow {
|
if follow {
|
||||||
match given_options.opt_str("s") {
|
match given_options.opt_str("s") {
|
||||||
Some(n) => {
|
Some(n) => {
|
||||||
let parsed: Option<u64> = from_str(n.as_slice());
|
let parsed: Option<u64> = n.parse();
|
||||||
match parsed {
|
match parsed {
|
||||||
Some(m) => { sleep_msec = m * 1000 }
|
Some(m) => { sleep_msec = m * 1000 }
|
||||||
None => {}
|
None => {}
|
||||||
|
@ -192,7 +192,7 @@ fn parse_size(mut size_slice: &str) -> Option<uint> {
|
||||||
// sole B is not a valid suffix
|
// sole B is not a valid suffix
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let value = from_str(size_slice);
|
let value = size_slice.parse();
|
||||||
match value {
|
match value {
|
||||||
Some(v) => Some(multiplier * v),
|
Some(v) => Some(multiplier * v),
|
||||||
None => None
|
None => None
|
||||||
|
@ -222,7 +222,7 @@ fn obsolete(options: &[String]) -> (Vec<String>, Option<uint>) {
|
||||||
// If this is the last number
|
// If this is the last number
|
||||||
if pos == len - 1 {
|
if pos == len - 1 {
|
||||||
options.remove(a);
|
options.remove(a);
|
||||||
let number: Option<uint> = from_str(from_utf8(current.slice(1,len)).unwrap());
|
let number: Option<uint> = from_utf8(current.slice(1,len)).unwrap().parse();
|
||||||
return (options, Some(number.unwrap()));
|
return (options, Some(number.unwrap()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ impl Uniq {
|
||||||
|
|
||||||
fn opt_parsed<T: FromStr>(opt_name: &str, matches: &getopts::Matches) -> Option<T> {
|
fn opt_parsed<T: FromStr>(opt_name: &str, matches: &getopts::Matches) -> Option<T> {
|
||||||
matches.opt_str(opt_name).map(|arg_str| {
|
matches.opt_str(opt_name).map(|arg_str| {
|
||||||
let opt_val: Option<T> = from_str(arg_str.as_slice());
|
let opt_val: Option<T> = arg_str.parse();
|
||||||
opt_val.unwrap_or_else(||
|
opt_val.unwrap_or_else(||
|
||||||
crash!(1, "Invalid argument for {}: {}", opt_name, arg_str))
|
crash!(1, "Invalid argument for {}: {}", opt_name, arg_str))
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue