File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -191,6 +191,10 @@ pub enum SortField {
191
191
/// bad, even though that’s kind of nonsensical. So it’s its own variant
192
192
/// that can be reversed like usual.
193
193
ModifiedAge ,
194
+
195
+ /// The file's name, however if the name of the file begins with `.`
196
+ /// ignore the leading `.` and then sort as Name
197
+ NameMixHidden ( SortCase ) ,
194
198
}
195
199
196
200
/// Whether a field should be sorted case-sensitively or case-insensitively.
@@ -253,6 +257,23 @@ impl SortField {
253
257
Ordering :: Equal => natord:: compare_ignore_case ( & * a. name , & * b. name ) ,
254
258
order => order,
255
259
} ,
260
+
261
+ SortField :: NameMixHidden ( ABCabc ) => natord:: compare (
262
+ SortField :: strip_dot ( & a. name ) ,
263
+ SortField :: strip_dot ( & b. name )
264
+ ) ,
265
+ SortField :: NameMixHidden ( AaBbCc ) => natord:: compare_ignore_case (
266
+ SortField :: strip_dot ( & a. name ) ,
267
+ SortField :: strip_dot ( & b. name )
268
+ )
269
+ }
270
+ }
271
+
272
+ fn strip_dot ( n : & str ) -> & str {
273
+ if n. starts_with ( "." ) {
274
+ & n[ 1 ..]
275
+ } else {
276
+ n
256
277
}
257
278
}
258
279
}
Original file line number Diff line number Diff line change @@ -41,6 +41,12 @@ impl SortField {
41
41
else if word == "Name" || word == "Filename" {
42
42
Ok ( SortField :: Name ( SortCase :: ABCabc ) )
43
43
}
44
+ else if word == ".name" || word == ".filename" {
45
+ Ok ( SortField :: NameMixHidden ( SortCase :: AaBbCc ) )
46
+ }
47
+ else if word == ".Name" || word == ".Filename" {
48
+ Ok ( SortField :: NameMixHidden ( SortCase :: ABCabc ) )
49
+ }
44
50
else if word == "size" || word == "filesize" {
45
51
Ok ( SortField :: Size )
46
52
}
@@ -231,6 +237,9 @@ mod test {
231
237
test ! ( newest: SortField <- [ "--sort=oldest" ] ; Both => Ok ( SortField :: ModifiedAge ) ) ;
232
238
test ! ( age: SortField <- [ "-sage" ] ; Both => Ok ( SortField :: ModifiedAge ) ) ;
233
239
240
+ test ! ( mix_hidden_lowercase: SortField <- [ "--sort" , ".name" ] ; Both => Ok ( SortField :: NameMixHidden ( SortCase :: AaBbCc ) ) ) ;
241
+ test ! ( mix_hidden_uppercase: SortField <- [ "--sort" , ".Name" ] ; Both => Ok ( SortField :: NameMixHidden ( SortCase :: ABCabc ) ) ) ;
242
+
234
243
// Errors
235
244
test ! ( error: SortField <- [ "--sort=colour" ] ; Both => Err ( Misfire :: BadArgument ( & flags:: SORT , OsString :: from( "colour" ) ) ) ) ;
236
245
You can’t perform that action at this time.
0 commit comments