1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #4266 from cakebaker/csplit_rename_var_and_simplify_format_strings

csplit: rename var to simplify format strings
This commit is contained in:
Sylvestre Ledru 2023-01-07 16:49:44 +01:00 committed by GitHub
commit 3033d017b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -55,7 +55,7 @@ impl SplitName {
let all = captures.name("ALL").unwrap();
let before = custom[0..all.start()].to_owned();
let after = custom[all.end()..].to_owned();
let n_digits = match captures.name("WIDTH") {
let width = match captures.name("WIDTH") {
None => 0,
Some(m) => m.as_str().parse::<usize>().unwrap(),
};
@ -82,47 +82,19 @@ impl SplitName {
*/
// decimal
("0", "d" | "i" | "u") => Box::new(move |n: usize| -> String {
format!(
"{}{}{:0width$}{}",
prefix,
before,
n,
after,
width = n_digits
)
format!("{}{}{:0width$}{}", prefix, before, n, after)
}),
// octal
("0", "o") => Box::new(move |n: usize| -> String {
format!(
"{}{}{:0width$o}{}",
prefix,
before,
n,
after,
width = n_digits
)
format!("{}{}{:0width$o}{}", prefix, before, n, after)
}),
// lower hexadecimal
("0", "x") => Box::new(move |n: usize| -> String {
format!(
"{}{}{:0width$x}{}",
prefix,
before,
n,
after,
width = n_digits
)
format!("{}{}{:0width$x}{}", prefix, before, n, after)
}),
// upper hexadecimal
("0", "X") => Box::new(move |n: usize| -> String {
format!(
"{}{}{:0width$X}{}",
prefix,
before,
n,
after,
width = n_digits
)
format!("{}{}{:0width$X}{}", prefix, before, n, after)
}),
/*
@ -130,36 +102,15 @@ impl SplitName {
*/
// octal
("#", "o") => Box::new(move |n: usize| -> String {
format!(
"{}{}{:>#width$o}{}",
prefix,
before,
n,
after,
width = n_digits
)
format!("{}{}{:>#width$o}{}", prefix, before, n, after)
}),
// lower hexadecimal
("#", "x") => Box::new(move |n: usize| -> String {
format!(
"{}{}{:>#width$x}{}",
prefix,
before,
n,
after,
width = n_digits
)
format!("{}{}{:>#width$x}{}", prefix, before, n, after)
}),
// upper hexadecimal
("#", "X") => Box::new(move |n: usize| -> String {
format!(
"{}{}{:>#width$X}{}",
prefix,
before,
n,
after,
width = n_digits
)
format!("{}{}{:>#width$X}{}", prefix, before, n, after)
}),
/*
@ -167,47 +118,19 @@ impl SplitName {
*/
// decimal
("-", "d" | "i" | "u") => Box::new(move |n: usize| -> String {
format!(
"{}{}{:<#width$}{}",
prefix,
before,
n,
after,
width = n_digits
)
format!("{}{}{:<#width$}{}", prefix, before, n, after)
}),
// octal
("-", "o") => Box::new(move |n: usize| -> String {
format!(
"{}{}{:<#width$o}{}",
prefix,
before,
n,
after,
width = n_digits
)
format!("{}{}{:<#width$o}{}", prefix, before, n, after)
}),
// lower hexadecimal
("-", "x") => Box::new(move |n: usize| -> String {
format!(
"{}{}{:<#width$x}{}",
prefix,
before,
n,
after,
width = n_digits
)
format!("{}{}{:<#width$x}{}", prefix, before, n, after)
}),
// upper hexadecimal
("-", "X") => Box::new(move |n: usize| -> String {
format!(
"{}{}{:<#width$X}{}",
prefix,
before,
n,
after,
width = n_digits
)
format!("{}{}{:<#width$X}{}", prefix, before, n, after)
}),
_ => return Err(CsplitError::SuffixFormatIncorrect),