actually use the standard library
it has the nice side effect of working better too, imagine that
This commit is contained in:
parent
be6885398b
commit
ead10096d7
|
@ -4,6 +4,7 @@ package files
|
|||
import (
|
||||
"cmp"
|
||||
"io/fs"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
@ -67,12 +68,14 @@ func SortByPathReverse(a, b File) int {
|
|||
}
|
||||
|
||||
func SortByExtension(a, b File) int {
|
||||
aext, bext := getExts(a, b)
|
||||
aext := filepath.Ext(a.Name())
|
||||
bext := filepath.Ext(b.Name())
|
||||
return cmp.Compare(aext, bext)
|
||||
}
|
||||
|
||||
func SortByExtensionReverse(a, b File) int {
|
||||
aext, bext := getExts(a, b)
|
||||
aext := filepath.Ext(a.Name())
|
||||
bext := filepath.Ext(b.Name())
|
||||
return cmp.Compare(bext, aext)
|
||||
}
|
||||
|
||||
|
@ -95,20 +98,3 @@ func SortDirectoriesLast(a, b File) int {
|
|||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
func getExts(a, b File) (string, string) {
|
||||
var aext, bext string
|
||||
as := strings.Split(a.Name(), ".")
|
||||
bs := strings.Split(b.Name(), ".")
|
||||
if len(as) <= 1 {
|
||||
aext = ""
|
||||
} else {
|
||||
aext = as[len(as)-1]
|
||||
}
|
||||
if len(bs) <= 1 {
|
||||
aext = ""
|
||||
} else {
|
||||
bext = bs[len(bs)-1]
|
||||
}
|
||||
return aext, bext
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue