(Feat): Initial Commit
This commit is contained in:
23
internal/util/lang.go
Normal file
23
internal/util/lang.go
Normal file
@@ -0,0 +1,23 @@
|
||||
// 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
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user