1
Fork 0
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:
Terts Diepraam 2021-06-11 17:10:52 +02:00 committed by GitHub
commit 7e47836e94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 11 deletions

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);

View file

@ -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');
}
}