Files
Gumble-Backend/internal/util/lang.go
Zane Walker 7e940c83a7
Some checks failed
Build & Test / build-test (push) Has been cancelled
Build & Test / swagger-codegen-cli (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
(Feat): Initial Commit
2026-07-03 19:41:31 +05:30

24 lines
632 B
Go

// nolint:revive
package util
import (
"sort"
"golang.org/x/text/collate"
"golang.org/x/text/language"
)
// SortCollateStringSlice is used to sort a slice of strings if the language specific order of caracters is
// important for the order of the string.
// ! The slice passed will be changed.
func SortCollateStringSlice(slice []string, lang language.Tag, options ...collate.Option) {
if len(options) == 0 {
options = []collate.Option{collate.IgnoreCase, collate.IgnoreWidth}
}
coll := collate.New(lang, options...)
sort.Slice(slice, func(i int, j int) bool {
return coll.CompareString(slice[i], slice[j]) < 0
})
}