1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 20:17:45 +00:00
This commit is contained in:
Reto Hablützel 2021-04-11 16:16:38 +02:00
parent 75a76613e4
commit b465c34eef
2 changed files with 5 additions and 4 deletions

View file

@ -1042,7 +1042,7 @@ fn sort_entries(entries: &mut Vec<PathBuf>, config: &Config) {
.sort_by_key(|k| Reverse(get_metadata(k, config).map(|md| md.len()).unwrap_or(0))),
// The default sort in GNU ls is case insensitive
Sort::Name => entries.sort_by_key(|k| k.to_string_lossy().to_lowercase()),
Sort::Version => entries.sort_by(version_cmp::version_cmp),
Sort::Version => entries.sort_by(|a, b| version_cmp::version_cmp(a, b)),
Sort::None => {}
}

View file

@ -1,8 +1,9 @@
use std::{cmp::Ordering, path::PathBuf};
use std::cmp::Ordering;
use std::path::Path;
/// Compare pathbufs in a way that matches the GNU version sort, meaning that
/// Compare paths in a way that matches the GNU version sort, meaning that
/// numbers get sorted in a natural way.
pub(crate) fn version_cmp(a: &PathBuf, b: &PathBuf) -> Ordering {
pub(crate) fn version_cmp(a: &Path, b: &Path) -> Ordering {
let a_string = a.to_string_lossy();
let b_string = b.to_string_lossy();
let mut a = a_string.chars().peekable();