MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / compareVersion

Function compareVersion

cli/cmd/update.go:167–195  ·  view source on GitHub ↗

比较两个版本号 version1 和 version2。 如果 version1 > version2 返回 1,如果 version1 < version2 返回 -1, 除此之外返回 0。

(version1 string, version2 string)

Source from the content-addressed store, hash-verified

165// 比较两个版本号 version1 和 version2。
166// 如果 version1 > version2 返回 1,如果 version1 < version2 返回 -1, 除此之外返回 0。
167func compareVersion(version1 string, version2 string) int {
168 var res int
169 ver1Strs := strings.Split(version1, ".")
170 ver2Strs := strings.Split(version2, ".")
171 ver1Len := len(ver1Strs)
172 ver2Len := len(ver2Strs)
173 verLen := ver1Len
174 if len(ver1Strs) < len(ver2Strs) {
175 verLen = ver2Len
176 }
177 for i := 0; i < verLen; i++ {
178 var ver1Int, ver2Int int
179 if i < ver1Len {
180 ver1Int, _ = strconv.Atoi(ver1Strs[i])
181 }
182 if i < ver2Len {
183 ver2Int, _ = strconv.Atoi(ver2Strs[i])
184 }
185 if ver1Int < ver2Int {
186 res = -1
187 break
188 }
189 if ver1Int > ver2Int {
190 res = 1
191 break
192 }
193 }
194 return res
195}
196
197func init() {
198 udpateCmd.Flags().BoolP("build", "b", false, i18n.GetInstance().Update.Info_help_flag_build)

Callers 1

update.goFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected