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:
parent
6003d95974
commit
6734d5df93
1 changed files with 1 additions and 8 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue