forked from fileformat/ghashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort.go
47 lines (35 loc) · 1.01 KB
/
sort.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"sort"
"golang.org/x/text/collate"
"golang.org/x/text/language"
github "github.com/google/go-github/v58/github"
)
func SortStringsCaseInsensitive(data []string) {
collator := collate.New(language.English)
collator.SortStrings(data)
}
func SortWorkflowsCaseInsensitive(data []*github.Workflow) {
collator := collate.New(language.English)
sort.Slice(data, func(i, j int) bool { return collator.CompareString(*data[i].Name, *data[j].Name) < 0 })
}
type MetaRepoSlice struct {
MetaRepos []*MetaRepo
}
func (mrs MetaRepoSlice) Len() int {
return len(mrs.MetaRepos)
}
func (mrs MetaRepoSlice) Swap(i, j int) {
temp := mrs.MetaRepos[i]
mrs.MetaRepos[i] = mrs.MetaRepos[j]
mrs.MetaRepos[j] = temp
}
func (mrs MetaRepoSlice) Bytes(i int) []byte {
// returns the bytes of text at index i
return []byte(*mrs.MetaRepos[i].Repo.FullName)
}
func SortReposCaseInsensitive(data []*MetaRepo) {
mrs := MetaRepoSlice{MetaRepos: data}
collator := collate.New(language.English)
collator.Sort(mrs)
}