1
1
mirror of https://github.com/go-gitea/gitea synced 2024-12-24 17:44:27 +00:00
gitea/vendor/github.com/mcuadros/go-version/sort.go

37 lines
689 B
Go
Raw Normal View History

2016-11-03 22:16:01 +00:00
package version
import (
"sort"
)
// Sorts a string slice of version number strings using version.CompareSimple()
//
// Example:
// version.Sort([]string{"1.10-dev", "1.0rc1", "1.0", "1.0-dev"})
// Returns []string{"1.0-dev", "1.0rc1", "1.0", "1.10-dev"}
//
func Sort(versionStrings []string) {
versions := versionSlice(versionStrings)
sort.Sort(versions)
}
type versionSlice []string
func (s versionSlice) Len() int {
return len(s)
}
func (s versionSlice) Less(i, j int) bool {
cmp := CompareSimple(Normalize(s[i]), Normalize(s[j]))
if cmp == 0 {
return s[i] < s[j]
}
return cmp < 0
}
func (s versionSlice) Swap(i, j int) {
tmp := s[j]
s[j] = s[i]
s[i] = tmp
}