MCPcopy
hub / github.com/writefreely/writefreely / CompareSemver

Function CompareSemver

semver.go:53–75  ·  view source on GitHub ↗

CompareSemver returns an integer comparing two versions according to according to semantic version precedence. The result will be 0 if v == w, -1 if v < w, or +1 if v > w. An invalid semantic version string is considered less than a valid one. All invalid semantic version strings compare equal to e

(v, w string)

Source from the content-addressed store, hash-verified

51// An invalid semantic version string is considered less than a valid one.
52// All invalid semantic version strings compare equal to each other.
53func CompareSemver(v, w string) int {
54 pv, ok1 := semParse(v)
55 pw, ok2 := semParse(w)
56 if !ok1 && !ok2 {
57 return 0
58 }
59 if !ok1 {
60 return -1
61 }
62 if !ok2 {
63 return +1
64 }
65 if c := compareInt(pv.major, pw.major); c != 0 {
66 return c
67 }
68 if c := compareInt(pv.minor, pw.minor); c != 0 {
69 return c
70 }
71 if c := compareInt(pv.patch, pw.patch); c != 0 {
72 return c
73 }
74 return comparePrerelease(pv.prerelease, pw.prerelease)
75}
76
77func semParse(v string) (p parsed, ok bool) {
78 if v == "" || v[0] != 'v' {

Callers 3

CheckNowMethod · 0.85
AreAvailableMethod · 0.85
AreAvailableNoCheckMethod · 0.85

Calls 3

semParseFunction · 0.85
compareIntFunction · 0.85
comparePrereleaseFunction · 0.85

Tested by

no test coverage detected