diff options
author | Unknwon <u@gogs.io> | 2017-02-09 19:48:13 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2017-02-09 19:48:13 -0500 |
commit | 2fd69f13d9599a6c58b47225565163fd7d87889f (patch) | |
tree | fd19e868e1c2e95a5fb83a268f6e393669d6ee79 /vendor/github.com/mcuadros/go-version/stability.go | |
parent | eb66060cd7b9bce996b1d75ae80ce1ef31d5ce62 (diff) |
vendor: check in vendors
Bye bye glide...
Diffstat (limited to 'vendor/github.com/mcuadros/go-version/stability.go')
-rw-r--r-- | vendor/github.com/mcuadros/go-version/stability.go | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/vendor/github.com/mcuadros/go-version/stability.go b/vendor/github.com/mcuadros/go-version/stability.go new file mode 100644 index 00000000..566f7d90 --- /dev/null +++ b/vendor/github.com/mcuadros/go-version/stability.go @@ -0,0 +1,83 @@ +package version + +import ( + "regexp" + "strings" +) + +const ( + Development = iota + Alpha + Beta + RC + Stable +) + +func expandStability(stability string) string { + stability = strings.ToLower(stability) + + switch stability { + case "a": + return "alpha" + case "b": + return "beta" + case "p": + return "patch" + case "pl": + return "patch" + case "rc": + return "RC" + } + + return stability +} + +func parseStability(version string) string { + version = regexp.MustCompile(`(?i)#.+$`).ReplaceAllString(version, " ") + version = strings.ToLower(version) + + if strings.HasPrefix(version, "dev-") || strings.HasSuffix(version, "-dev") { + return "dev" + } + + result := RegFind(`(?i)^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?`+modifierRegex+`$`, version) + if result != nil { + if len(result) > 3 { + return "dev" + } + } + + if result[1] != "" { + if "beta" == result[1] || "b" == result[1] { + return "beta" + } + if "alpha" == result[1] || "a" == result[1] { + return "alpha" + } + if "rc" == result[1] { + return "RC" + } + } + + return "stable" +} + +func GetStability(version string) int { + result := RegFind(`(?i)(stable|RC|beta|alpha|dev)`, Normalize(version)) + if len(result) == 0 { + return Stable + } + + switch result[1] { + case "dev": + return Development + case "alpha": + return Alpha + case "beta": + return Beta + case "RC": + return RC + } + + return Stable +} |