mirror of
https://github.com/Llewellynvdm/exa.git
synced 2025-01-11 16:34:26 +00:00
Sort case-insensitively
This commit is contained in:
parent
4722c8991b
commit
a631bc099f
@ -4,6 +4,7 @@ use file::File;
|
||||
use std::cmp::lexical_ordering;
|
||||
use column::{Column, Permissions, FileName, FileSize, User, Group};
|
||||
use unix::get_current_user_id;
|
||||
use std::ascii::StrAsciiExt;
|
||||
|
||||
pub enum SortField {
|
||||
Name, Extension, Size
|
||||
@ -83,8 +84,8 @@ impl Options {
|
||||
Name => files.sort_by(|a, b| a.parts.cmp(&b.parts)),
|
||||
Size => files.sort_by(|a, b| a.stat.size.cmp(&b.stat.size)),
|
||||
Extension => files.sort_by(|a, b| {
|
||||
let exts = a.ext.cmp(&b.ext);
|
||||
let names = a.name.cmp(&b.name);
|
||||
let exts = a.ext.map(|e| e.to_ascii_lower()).cmp(&b.ext.map(|e| e.to_ascii_lower()));
|
||||
let names = a.name.to_ascii_lower().cmp(&b.name.to_ascii_lower());
|
||||
lexical_ordering(exts, names)
|
||||
}),
|
||||
}
|
||||
|
10
sort.rs
10
sort.rs
@ -1,3 +1,5 @@
|
||||
use std::ascii::StrAsciiExt;
|
||||
|
||||
// This is an implementation of "natural sort order". See
|
||||
// http://blog.codinghorror.com/sorting-for-humans-natural-sort-order/
|
||||
// for more information and examples. It tries to sort "9" before
|
||||
@ -9,16 +11,16 @@
|
||||
|
||||
#[deriving(Eq, Ord, TotalEq, TotalOrd)]
|
||||
pub enum SortPart<'a> {
|
||||
Stringular(&'a str),
|
||||
Numeric(u32),
|
||||
Numeric(u64),
|
||||
Stringular(String),
|
||||
}
|
||||
|
||||
impl<'a> SortPart<'a> {
|
||||
pub fn from_string(is_digit: bool, slice: &'a str) -> SortPart<'a> {
|
||||
if is_digit {
|
||||
Numeric(from_str::<u32>(slice).unwrap())
|
||||
Numeric(from_str::<u64>(slice).expect(slice.to_owned()))
|
||||
} else {
|
||||
Stringular(slice)
|
||||
Stringular(slice.to_ascii_lower())
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user