mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
Merge pull request #2400 from youknowone/line-ends
cleaning up str ends checks
This commit is contained in:
commit
7e47836e94
2 changed files with 3 additions and 11 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);
|
||||
|
|
|
@ -50,9 +50,8 @@ fn mkdelim(col: usize, opts: &ArgMatches) -> String {
|
|||
}
|
||||
|
||||
fn ensure_nl(line: &mut String) {
|
||||
match line.chars().last() {
|
||||
Some('\n') => (),
|
||||
_ => line.push('\n'),
|
||||
if !line.ends_with('\n') {
|
||||
line.push('\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue