1
2
3
4
5 package cpu
6
7 import "strconv"
8
9
10
11
12
13
14 func parseRelease(rel string) (major, minor, patch int, ok bool) {
15
16 for i := 0; i < len(rel); i++ {
17 if rel[i] == '-' || rel[i] == '+' {
18 rel = rel[:i]
19 break
20 }
21 }
22
23 next := func() (int, bool) {
24 for i := 0; i < len(rel); i++ {
25 if rel[i] == '.' {
26 ver, err := strconv.Atoi(rel[:i])
27 rel = rel[i+1:]
28 return ver, err == nil
29 }
30 }
31 ver, err := strconv.Atoi(rel)
32 rel = ""
33 return ver, err == nil
34 }
35 if major, ok = next(); !ok || rel == "" {
36 return
37 }
38 if minor, ok = next(); !ok || rel == "" {
39 return
40 }
41 patch, ok = next()
42 return
43 }
44
View as plain text