MCPcopy Create free account
hub / github.com/Debian/dcs / verrevcmp

Function verrevcmp

dpkgversion/dpkgversion.go:55–103  ·  view source on GitHub ↗
(a string, b string)

Source from the content-addressed store, hash-verified

53}
54
55func verrevcmp(a string, b string) int {
56 i := 0
57 j := 0
58 for i < len(a) || j < len(b) {
59 var first_diff int
60 for (i < len(a) && !cisdigit(rune(a[i]))) ||
61 (j < len(b) && !cisdigit(rune(b[j]))) {
62 ac := 0
63 if i < len(a) {
64 ac = order(rune(a[i]))
65 }
66 bc := 0
67 if j < len(b) {
68 bc = order(rune(b[j]))
69 }
70 if ac != bc {
71 return ac - bc
72 }
73 i++
74 j++
75 }
76
77 for i < len(a) && a[i] == '0' {
78 i++
79 }
80 for j < len(b) && b[j] == '0' {
81 j++
82 }
83
84 for i < len(a) && cisdigit(rune(a[i])) && j < len(b) && cisdigit(rune(b[j])) {
85 if first_diff == 0 {
86 first_diff = int(rune(a[i]) - rune(b[j]))
87 }
88 i++
89 j++
90 }
91
92 if i < len(a) && cisdigit(rune(a[i])) {
93 return 1
94 }
95 if j < len(b) && cisdigit(rune(b[j])) {
96 return -1
97 }
98 if first_diff != 0 {
99 return first_diff
100 }
101 }
102 return 0
103}
104
105// Compare compares the two provided Debian versions. It returns 0 if a and b
106// are equal, a value < 0 if a is smaller than b and a value > 0 if a is

Callers 1

CompareFunction · 0.85

Calls 2

cisdigitFunction · 0.85
orderFunction · 0.85

Tested by

no test coverage detected