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