1
0
mirror of https://github.com/nitezs/sub2sing-box.git synced 2024-12-24 12:54:41 -05:00
sub2sing-box/model/sort.go

28 lines
764 B
Go
Raw Normal View History

2024-03-19 09:02:53 -04:00
package model
import (
"golang.org/x/text/collate"
"golang.org/x/text/language"
)
type SortByNumber []Outbound
func (a SortByNumber) Len() int { return len(a) }
func (a SortByNumber) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortByNumber) Less(i, j int) bool { return len(a[i].Outbounds) < len(a[j].Outbounds) }
type SortByTag []Outbound
func (a SortByTag) Len() int { return len(a) }
func (a SortByTag) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortByTag) Less(i, j int) bool {
tags := []language.Tag{
language.English,
language.Chinese,
}
matcher := language.NewMatcher(tags)
bestMatch, _, _ := matcher.Match(language.Make("zh"))
c := collate.New(bestMatch)
return c.CompareString(a[i].Tag, a[j].Tag) < 0
}