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

refactor/uucore ~ align return values for executable/util macros

This commit is contained in:
Roy Ivy III 2021-07-28 16:18:42 -05:00 committed by Michael Debertol
parent eb13533e4e
commit 69ce4dc8e5

View file

@ -20,7 +20,7 @@ macro_rules! executable(
let exe = match $crate::executable_os!().to_str() {
// * UTF-8
Some(s) => s.to_string(),
// * "lossless" debug format if `executable_os!()` is not well-formed UTF-8
// * "lossless" debug format (if/when `executable_os!()` is not well-formed UTF-8)
None => format!("{:?}", $crate::executable_os!())
};
&exe.to_owned()
@ -31,7 +31,14 @@ macro_rules! executable(
#[macro_export]
macro_rules! executable_name(
() => ({
&std::path::Path::new($crate::executable_os!()).file_stem().unwrap().to_string_lossy()
let stem = &std::path::Path::new($crate::executable_os!()).file_stem().unwrap().to_owned();
let exe = match stem.to_str() {
// * UTF-8
Some(s) => s.to_string(),
// * "lossless" debug format (if/when `executable_os!()` is not well-formed UTF-8)
None => format!("{:?}", stem)
};
&exe.to_owned()
})
);
@ -40,11 +47,12 @@ macro_rules! executable_name(
macro_rules! util_name(
() => ({
let crate_name = env!("CARGO_PKG_NAME");
if crate_name.starts_with("uu_") {
let name = if crate_name.starts_with("uu_") {
&crate_name[3..]
} else {
&crate_name
}
crate_name
};
&name.to_owned()
})
);