2014-02-21 18:15:28 -05:00
|
|
|
package version
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Version string
|
|
|
|
|
2014-04-01 18:46:52 -04:00
|
|
|
func (me Version) compareTo(other Version) int {
|
2014-02-21 18:15:28 -05:00
|
|
|
var (
|
|
|
|
meTab = strings.Split(string(me), ".")
|
2014-04-01 18:46:52 -04:00
|
|
|
otherTab = strings.Split(string(other), ".")
|
2014-02-21 18:15:28 -05:00
|
|
|
)
|
|
|
|
for i, s := range meTab {
|
|
|
|
var meInt, otherInt int
|
|
|
|
meInt, _ = strconv.Atoi(s)
|
|
|
|
if len(otherTab) > i {
|
|
|
|
otherInt, _ = strconv.Atoi(otherTab[i])
|
|
|
|
}
|
|
|
|
if meInt > otherInt {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
if otherInt > meInt {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(otherTab) > len(meTab) {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2014-04-01 18:46:52 -04:00
|
|
|
func (me Version) LessThan(other Version) bool {
|
2014-02-21 18:15:28 -05:00
|
|
|
return me.compareTo(other) == -1
|
|
|
|
}
|
|
|
|
|
2014-04-01 18:46:52 -04:00
|
|
|
func (me Version) LessThanOrEqualTo(other Version) bool {
|
2014-02-21 18:15:28 -05:00
|
|
|
return me.compareTo(other) <= 0
|
|
|
|
}
|
|
|
|
|
2014-04-01 18:46:52 -04:00
|
|
|
func (me Version) GreaterThan(other Version) bool {
|
2014-02-21 18:15:28 -05:00
|
|
|
return me.compareTo(other) == 1
|
|
|
|
}
|
|
|
|
|
2014-04-01 18:46:52 -04:00
|
|
|
func (me Version) GreaterThanOrEqualTo(other Version) bool {
|
2014-02-21 18:15:28 -05:00
|
|
|
return me.compareTo(other) >= 0
|
|
|
|
}
|
|
|
|
|
2014-04-01 18:46:52 -04:00
|
|
|
func (me Version) Equal(other Version) bool {
|
2014-02-21 18:15:28 -05:00
|
|
|
return me.compareTo(other) == 0
|
|
|
|
}
|