diff options
author | Ben S <ogham@bsago.me> | 2016-03-19 14:53:09 +0000 |
---|---|---|
committer | Ben S <ogham@bsago.me> | 2016-03-19 15:06:26 +0000 |
commit | 8805ce9e3bcd4b56f8811a686dd56c47202cdbab (patch) | |
tree | 4767461e0423a2b1f51172b61551b8279ece8121 | |
parent | 3e9616cffababc491b1fa587e008a0bdb385901c (diff) |
Add case-insensitive extension sorting
This finishes off and closes #102. The code in this and the previous commit
were partly authored by `zv0n` on GitHub.
-rw-r--r-- | src/options.rs | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/src/options.rs b/src/options.rs index 9ff9e86..07af65b 100644 --- a/src/options.rs +++ b/src/options.rs @@ -366,18 +366,26 @@ impl FileFilter { use self::SortCase::{Sensitive, Insensitive}; match self.sort_field { - SortField::Unsorted => cmp::Ordering::Equal, - SortField::Name(Sensitive) => natord::compare(&a.name, &b.name), - SortField::Name(Insensitive) => natord::compare_ignore_case(&a.name, &b.name), - SortField::Size => a.metadata.len().cmp(&b.metadata.len()), - SortField::FileInode => a.metadata.ino().cmp(&b.metadata.ino()), - SortField::ModifiedDate => a.metadata.mtime().cmp(&b.metadata.mtime()), - SortField::AccessedDate => a.metadata.atime().cmp(&b.metadata.atime()), - SortField::CreatedDate => a.metadata.ctime().cmp(&b.metadata.ctime()), - SortField::Extension => match a.ext.cmp(&b.ext) { + SortField::Unsorted => cmp::Ordering::Equal, + + SortField::Name(Sensitive) => natord::compare(&a.name, &b.name), + SortField::Name(Insensitive) => natord::compare_ignore_case(&a.name, &b.name), + + SortField::Size => a.metadata.len().cmp(&b.metadata.len()), + SortField::FileInode => a.metadata.ino().cmp(&b.metadata.ino()), + SortField::ModifiedDate => a.metadata.mtime().cmp(&b.metadata.mtime()), + SortField::AccessedDate => a.metadata.atime().cmp(&b.metadata.atime()), + SortField::CreatedDate => a.metadata.ctime().cmp(&b.metadata.ctime()), + + SortField::Extension(Sensitive) => match a.ext.cmp(&b.ext) { cmp::Ordering::Equal => natord::compare(&*a.name, &*b.name), order => order, }, + + SortField::Extension(Insensitive) => match a.ext.cmp(&b.ext) { + cmp::Ordering::Equal => natord::compare_ignore_case(&*a.name, &*b.name), + order => order, + }, } } } @@ -462,12 +470,14 @@ impl RecurseOptions { /// User-supplied field to sort by. #[derive(PartialEq, Debug, Copy, Clone)] pub enum SortField { - Unsorted, Name(SortCase), Extension, Size, FileInode, + Unsorted, + Name(SortCase), Extension(SortCase), + Size, FileInode, ModifiedDate, AccessedDate, CreatedDate, } /// Whether a field should be sorted case-sensitively or case-insensitively. -/// +/// /// This determines which of the `natord` functions to use. #[derive(PartialEq, Debug, Copy, Clone)] pub enum SortCase { @@ -488,7 +498,8 @@ impl OptionSet for SortField { "name" | "filename" => Ok(SortField::Name(SortCase::Sensitive)), "Name" | "Filename" => Ok(SortField::Name(SortCase::Insensitive)), "size" | "filesize" => Ok(SortField::Size), - "ext" | "extension" => Ok(SortField::Extension), + "ext" | "extension" => Ok(SortField::Extension(SortCase::Sensitive)), + "Ext" | "Extension" => Ok(SortField::Extension(SortCase::Insensitive)), "mod" | "modified" => Ok(SortField::ModifiedDate), "acc" | "accessed" => Ok(SortField::AccessedDate), "cr" | "created" => Ok(SortField::CreatedDate), |