1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-31 21:17:46 +00:00

str::from_str removal/changes

This commit is contained in:
Michael Gehring 2015-01-08 14:01:22 +01:00
parent 7d8053561e
commit fd69e7fa4a
10 changed files with 24 additions and 25 deletions

View file

@ -23,19 +23,19 @@ impl std::str::FromStr for Range {
match (parts.next(), parts.next()) {
(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 })
}
(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 })
}
(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 })
}
(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(Range { low: low, high: high })
}
@ -54,7 +54,7 @@ impl Range {
let mut ranges = vec!();
for item in list.split(',') {
match from_str::<Range>(item) {
match std::str::FromStr::from_str(item) {
Some(range_item) => ranges.push(range_item),
None => return Err(format!("range '{}' was invalid", item))
}

View file

@ -13,7 +13,7 @@ extern crate getopts;
extern crate libc;
use std::io;
use std::str::from_str;
use std::str::StrExt;
#[path = "../common/util.rs"]
#[macro_use]
@ -28,7 +28,7 @@ fn tabstops_parse(s: String) -> Vec<uint> {
let words = s.as_slice().split(',').collect::<Vec<&str>>();
let nums = words.into_iter()
.map(|sn| from_str::<uint>(sn)
.map(|sn| sn.parse::<uint>()
.unwrap_or_else(
|| crash!(1, "{}\n", "tab size contains invalid character(s)"))
)

View file

@ -56,7 +56,7 @@ fn print_factors(num: u64) {
}
fn print_factors_str(num_str: &str) {
let num = match from_str(num_str) {
let num = match num_str.parse::<u64>() {
Some(x) => x,
None => { crash!(1, "{} not a number", num_str); }
};

View file

@ -140,7 +140,7 @@ pub fn uumain(args: Vec<String>) -> int {
match matches.opt_str("w") {
Some(s) => {
fmt_opts.width =
match from_str(s.as_slice()) {
match s.parse::<uint>() {
Some(t) => t,
None => { crash!(1, "Invalid WIDTH specification: `{}'", s); }
};
@ -152,7 +152,7 @@ pub fn uumain(args: Vec<String>) -> int {
match matches.opt_str("g") {
Some(s) => {
fmt_opts.goal =
match from_str(s.as_slice()) {
match s.parse::<uint>() {
Some(t) => t,
None => { crash!(1, "Invalid GOAL specification: `{}'", s); }
};
@ -168,7 +168,7 @@ pub fn uumain(args: Vec<String>) -> int {
match matches.opt_str("T") {
Some(s) => {
fmt_opts.tabwidth =
match from_str(s.as_slice()) {
match s.parse::<uint>() {
Some(t) => t,
None => { crash!(1, "Invalid TABWIDTH specification: `{}'", s); }
};

View file

@ -62,7 +62,7 @@ pub fn uumain(args: Vec<String>) -> int {
}
};
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,
None => crash!(1, "illegal width value (\"{}\")", inp_width)
},

View file

@ -68,7 +68,7 @@ pub fn uumain(args: Vec<String>) -> int {
show_error!("cannot specify both --bytes and --lines.");
return 1;
}
match from_str(n.as_slice()) {
match n.parse::<uint>() {
Some(m) => { line_count = m }
None => {
show_error!("invalid line count '{}'", n);
@ -77,7 +77,7 @@ pub fn uumain(args: Vec<String>) -> int {
}
}
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,
None => {
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 pos == len - 1 {
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()));
}
}

View file

@ -52,7 +52,7 @@ pub fn uumain(args: Vec<String>) -> int {
}
let mut ignore = match matches.opt_str("ignore") {
Some(numstr) => match from_str(numstr.as_slice()) {
Some(numstr) => match numstr.parse() {
Some(num) => num,
None => {
show_error!("\"{}\" is not a valid number", numstr);
@ -64,7 +64,7 @@ pub fn uumain(args: Vec<String>) -> int {
if !matches.opt_present("all") {
ignore += match os::getenv("OMP_NUM_THREADS") {
Some(threadstr) => match from_str(threadstr.as_slice()) {
Some(threadstr) => match threadstr.parse() {
Some(num) => num,
None => 0
},

View file

@ -13,7 +13,6 @@ extern crate getopts;
extern crate libc;
use std::cmp;
use std::str::from_str;
use std::io;
use std::io::IoResult;
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 zero = matches.opt_present("zero-terminated");
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,
None => {
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 {
Err(("invalid range format".to_string(), 1))
} else {
let begin = match from_str::<uint>(split[0]) {
let begin = match split[0].parse::<uint>() {
Some(m) => m,
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,
None => return Err((format!("{} is not a valid number", split[1]), 1))
};

View file

@ -71,7 +71,7 @@ pub fn uumain(args: Vec<String>) -> int {
if follow {
match given_options.opt_str("s") {
Some(n) => {
let parsed: Option<u64> = from_str(n.as_slice());
let parsed: Option<u64> = n.parse();
match parsed {
Some(m) => { sleep_msec = m * 1000 }
None => {}
@ -192,7 +192,7 @@ fn parse_size(mut size_slice: &str) -> Option<uint> {
// sole B is not a valid suffix
None
} else {
let value = from_str(size_slice);
let value = size_slice.parse();
match value {
Some(v) => Some(multiplier * v),
None => None
@ -222,7 +222,7 @@ fn obsolete(options: &[String]) -> (Vec<String>, Option<uint>) {
// If this is the last number
if pos == len - 1 {
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()));
}
}

View file

@ -111,7 +111,7 @@ impl Uniq {
fn opt_parsed<T: FromStr>(opt_name: &str, matches: &getopts::Matches) -> Option<T> {
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(||
crash!(1, "Invalid argument for {}: {}", opt_name, arg_str))
})