actually use the standard library

it has the nice side effect of working better too, imagine that
This commit is contained in:
Lilian Jónsdóttir 2024-07-21 20:33:25 -07:00
parent be6885398b
commit ead10096d7

View file

@ -4,6 +4,7 @@ package files
import ( import (
"cmp" "cmp"
"io/fs" "io/fs"
"path/filepath"
"strings" "strings"
"time" "time"
) )
@ -67,12 +68,14 @@ func SortByPathReverse(a, b File) int {
} }
func SortByExtension(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) return cmp.Compare(aext, bext)
} }
func SortByExtensionReverse(a, b File) int { 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) return cmp.Compare(bext, aext)
} }
@ -95,20 +98,3 @@ func SortDirectoriesLast(a, b File) int {
return 0 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
}