1
1
mirror of https://github.com/go-gitea/gitea synced 2024-11-16 15:14:24 +00:00
gitea/vendor/github.com/mcuadros/go-version/sort.go
2016-11-04 08:43:11 +01:00

37 lines
689 B
Go

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
}