@@ -16,8 +16,6 @@ import (
16
16
"time"
17
17
18
18
"github.com/djherbis/times"
19
- "golang.org/x/text/collate"
20
- "golang.org/x/text/language"
21
19
)
22
20
23
21
type linkState byte
@@ -247,24 +245,35 @@ func (dir *dir) sort() {
247
245
dir .files = filtered
248
246
}
249
247
250
- collopts := []collate.Option {}
251
- if dir .ignorecase {
252
- collopts = append (collopts , collate .IgnoreCase )
248
+ normalizefun := func (s1 , s2 string ) (string , string ) {
249
+ return s1 , s2
253
250
}
254
- if dir .ignoredia {
255
- collopts = append (collopts , collate .IgnoreDiacritics )
256
- }
257
- if dir .sortby == naturalSort {
258
- collopts = append (collopts , collate .Numeric )
251
+ if dir .ignorecase && dir .ignoredia {
252
+ normalizefun = func (s1 , s2 string ) (string , string ) {
253
+ return removeDiacritics (strings .ToLower (s1 )), removeDiacritics (strings .ToLower (s2 ))
254
+ }
255
+ } else if dir .ignorecase {
256
+ normalizefun = func (s1 , s2 string ) (string , string ) {
257
+ return strings .ToLower (s1 ), strings .ToLower (s2 )
258
+ }
259
+ } else if dir .ignoredia {
260
+ normalizefun = func (s1 , s2 string ) (string , string ) {
261
+ return removeDiacritics (s1 ), removeDiacritics (s2 )
262
+ }
259
263
}
260
- coll := collate .New (language .Und , collopts ... )
261
264
262
265
var lessfun func (i , j int ) bool
263
266
264
267
switch dir .sortby {
265
- case nameSort , naturalSort :
268
+ case naturalSort :
266
269
lessfun = func (i , j int ) bool {
267
- return coll .CompareString (dir .files [i ].Name (), dir .files [j ].Name ()) == - 1
270
+ s1 , s2 := normalizefun (dir .files [i ].Name (), dir .files [j ].Name ())
271
+ return naturalLess (s1 , s2 )
272
+ }
273
+ case nameSort :
274
+ lessfun = func (i , j int ) bool {
275
+ s1 , s2 := normalizefun (dir .files [i ].Name (), dir .files [j ].Name ())
276
+ return s1 < s2
268
277
}
269
278
case sizeSort :
270
279
lessfun = func (i , j int ) bool {
@@ -284,8 +293,16 @@ func (dir *dir) sort() {
284
293
}
285
294
case extSort :
286
295
lessfun = func (i , j int ) bool {
287
- cmp := coll .CompareString (dir .files [i ].ext , dir .files [j ].ext )
288
- return cmp == - 1 || cmp == 0 && coll .CompareString (dir .files [i ].Name (), dir .files [j ].Name ()) == - 1
296
+ ext1 , ext2 := normalizefun (dir .files [i ].ext , dir .files [j ].ext )
297
+ extcmp := strings .Compare (ext1 , ext2 )
298
+ if extcmp == - 1 {
299
+ return true
300
+ }
301
+ if extcmp == 0 {
302
+ name1 , name2 := normalizefun (dir .files [i ].Name (), dir .files [j ].Name ())
303
+ return name1 < name2
304
+ }
305
+ return false
289
306
}
290
307
}
291
308
0 commit comments