MCPcopy Create free account
hub / github.com/SwishHQ/spread / FormatVersionStr

Function FormatVersionStr

utils/common.go:93–111  ·  view source on GitHub ↗

given a version string, return a number example: 1.2.3 -> 10203 how it works: 1. split the version string by "." 2. reverse the array 3. for each element, convert it to an integer 4. multiply the integer by 100^index 5. add the integer to the total 6. return the total

(v string)

Source from the content-addressed store, hash-verified

91// 5. add the integer to the total
92// 6. return the total
93func FormatVersionStr(v string) int64 {
94 vs := strings.Split(v, ".")
95 if len(vs) <= 0 {
96 log.Panic("Version str error")
97 }
98 var vNum int64
99 ReverseArr(vs)
100 for index, v := range vs {
101 num, err := strconv.ParseInt(v, 10, 64)
102 if err != nil {
103 log.Panic(err.Error())
104 }
105 for i := 0; i < index; i++ {
106 num = num * 100
107 }
108 vNum += num
109 }
110 return vNum
111}
112
113func ReverseArr(s interface{}) {
114 sort.SliceStable(s, func(i, j int) bool {

Callers 2

CheckUpdateMethod · 0.92
CreateNewBundleMethod · 0.92

Calls 1

ReverseArrFunction · 0.85

Tested by

no test coverage detected