From ead10096d7c964cf6f9ac1e3d2e36ad661968a41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Sun, 21 Jul 2024 20:33:25 -0700 Subject: [PATCH] actually use the standard library it has the nice side effect of working better too, imagine that --- internal/files/files.go | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/internal/files/files.go b/internal/files/files.go index b871d09..2ceee52 100644 --- a/internal/files/files.go +++ b/internal/files/files.go @@ -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 -}