@@ -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
@@ -249,24 +247,35 @@ func (dir *dir) sort() {
249
247
dir .files = filtered
250
248
}
251
249
252
- collopts := []collate.Option {}
253
- if dir .ignorecase {
254
- collopts = append (collopts , collate .IgnoreCase )
250
+ normalizefun := func (s1 , s2 string ) (string , string ) {
251
+ return s1 , s2
255
252
}
256
- if dir .ignoredia {
257
- collopts = append (collopts , collate .IgnoreDiacritics )
258
- }
259
- if dir .sortby == naturalSort {
260
- collopts = append (collopts , collate .Numeric )
253
+ if dir .ignorecase && dir .ignoredia {
254
+ normalizefun = func (s1 , s2 string ) (string , string ) {
255
+ return removeDiacritics (strings .ToLower (s1 )), removeDiacritics (strings .ToLower (s2 ))
256
+ }
257
+ } else if dir .ignorecase {
258
+ normalizefun = func (s1 , s2 string ) (string , string ) {
259
+ return strings .ToLower (s1 ), strings .ToLower (s2 )
260
+ }
261
+ } else if dir .ignoredia {
262
+ normalizefun = func (s1 , s2 string ) (string , string ) {
263
+ return removeDiacritics (s1 ), removeDiacritics (s2 )
264
+ }
261
265
}
262
- coll := collate .New (language .Und , collopts ... )
263
266
264
267
var lessfun func (i , j int ) bool
265
268
266
269
switch dir .sortby {
267
- case nameSort , naturalSort :
270
+ case naturalSort :
268
271
lessfun = func (i , j int ) bool {
269
- return coll .CompareString (dir .files [i ].Name (), dir .files [j ].Name ()) == - 1
272
+ s1 , s2 := normalizefun (dir .files [i ].Name (), dir .files [j ].Name ())
273
+ return naturalLess (s1 , s2 )
274
+ }
275
+ case nameSort :
276
+ lessfun = func (i , j int ) bool {
277
+ s1 , s2 := normalizefun (dir .files [i ].Name (), dir .files [j ].Name ())
278
+ return s1 < s2
270
279
}
271
280
case sizeSort :
272
281
lessfun = func (i , j int ) bool {
@@ -286,8 +295,16 @@ func (dir *dir) sort() {
286
295
}
287
296
case extSort :
288
297
lessfun = func (i , j int ) bool {
289
- cmp := coll .CompareString (dir .files [i ].ext , dir .files [j ].ext )
290
- return cmp == - 1 || cmp == 0 && coll .CompareString (dir .files [i ].Name (), dir .files [j ].Name ()) == - 1
298
+ ext1 , ext2 := normalizefun (dir .files [i ].ext , dir .files [j ].ext )
299
+ extcmp := strings .Compare (ext1 , ext2 )
300
+ if extcmp == - 1 {
301
+ return true
302
+ }
303
+ if extcmp == 0 {
304
+ name1 , name2 := normalizefun (dir .files [i ].Name (), dir .files [j ].Name ())
305
+ return name1 < name2
306
+ }
307
+ return false
291
308
}
292
309
}
293
310
0 commit comments