1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 20:17:45 +00:00

basename: trim separators with function

This commit is contained in:
Jeong YunWon 2021-06-11 19:51:55 +09:00
parent 6003d95974
commit 6734d5df93

View file

@ -118,14 +118,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
fn basename(fullname: &str, suffix: &str) -> String {
// Remove all platform-specific path separators from the end
let mut path: String = fullname
.chars()
.rev()
.skip_while(|&ch| is_separator(ch))
.collect();
// Undo reverse
path = path.chars().rev().collect();
let path = fullname.trim_end_matches(is_separator);
// Convert to path buffer and get last path component
let pb = PathBuf::from(path);