@@ -23,15 +23,17 @@ import (
2323
2424// ----- type definitions -----
2525
26- // version is a composer-normalized version: 4 numeric parts.
27- type version [4 ]int
26+ // version is a composer-normalized version with 4 numeric parts.
27+ type version struct {
28+ parts [4 ]int
29+ }
2830
2931var versionRe = regexp .MustCompile (`(?i)^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?$` )
3032
3133func (v version ) cmp (o version ) int {
32- for i := range v {
33- if v [i ] != o [i ] {
34- if v [i ] < o [i ] {
34+ for i := range v . parts {
35+ if v . parts [i ] != o . parts [i ] {
36+ if v . parts [i ] < o . parts [i ] {
3537 return - 1
3638 }
3739 return 1
@@ -42,9 +44,9 @@ func (v version) cmp(o version) int {
4244
4345// bump returns v with the digit at index idx incremented and all later digits zeroed.
4446func (v version ) bump (idx int ) version {
45- v [idx ]++
46- for i := idx + 1 ; i < len (v ); i ++ {
47- v [i ] = 0
47+ v . parts [idx ]++
48+ for i := idx + 1 ; i < len (v . parts ); i ++ {
49+ v . parts [i ] = 0
4850 }
4951 return v
5052}
@@ -70,14 +72,14 @@ func (v version) holds(p comparator) bool {
7072
7173// next returns the successor in the discrete 4-part version space.
7274func (v version ) next () version {
73- v [3 ]++
75+ v . parts [3 ]++
7476 return v
7577}
7678
7779func (v version ) String () string {
78- parts := []string {strconv .Itoa (v [0 ]), strconv .Itoa (v [1 ]), strconv .Itoa (v [2 ])}
79- if v [3 ] != 0 {
80- parts = append (parts , strconv .Itoa (v [3 ]))
80+ parts := []string {strconv .Itoa (v . parts [0 ]), strconv .Itoa (v . parts [1 ]), strconv .Itoa (v . parts [2 ])}
81+ if v . parts [3 ] != 0 {
82+ parts = append (parts , strconv .Itoa (v . parts [3 ]))
8183 }
8284 return strings .Join (parts , "." )
8385}
@@ -101,7 +103,7 @@ func parseDigits(s string) (version, int, error) {
101103 n := 0
102104 for i , g := range m [1 :] {
103105 if g != "" {
104- v [i ], _ = strconv .Atoi (g )
106+ v . parts [i ], _ = strconv .Atoi (g )
105107 n ++
106108 }
107109 }
@@ -179,7 +181,7 @@ func parseConstraint(token string) ([]comparator, error) {
179181 // if none found, bump the last supplied
180182 idx := n - 1
181183 for i := 0 ; i < n ; i ++ {
182- if v [i ] != 0 {
184+ if v . parts [i ] != 0 {
183185 idx = i
184186 break
185187 }
@@ -197,7 +199,7 @@ func parseConstraint(token string) ([]comparator, error) {
197199 n := 0
198200 for i , g := range m [1 :4 ] {
199201 if g != "" {
200- low [i ], _ = strconv .Atoi (g )
202+ low . parts [i ], _ = strconv .Atoi (g )
201203 n ++
202204 }
203205 }
0 commit comments