Debian Codegraph @

spdxexp/compare.go

raw symbols SCIP
1 package spdxexp
2
3 // The compare methods determine if two ranges are greater than, less than or equal within the same license group.
4 // NOTE: Ranges are organized into groups (referred to as license groups) of the same base license (e.g. GPL).
5 // Groups have sub-groups of license versions (referred to as the range) where each member is considered
6 // to be the same version (e.g. {GPL-2.0, GPL-2.0-only}). The sub-groups are in ascending order within
7 // the license group, such that the first sub-group is considered to be less than the second sub-group,
8 // and so on. (e.g. {{GPL-1.0}, {GPL-2.0, GPL-2.0-only}} implies {GPL-1.0} < {GPL-2.0, GPL-2.0-only}).
9
10 // compareGT returns true if the first range is greater than the second range within the same license group; otherwise, false.
11 func compareGT(first *node, second *node) bool {
12 if !first.isLicense() || !second.isLicense() {
13 return false
14 }
15 firstRange := getLicenseRange(*first.license())
16 secondRange := getLicenseRange(*second.license())
17
18 if !sameLicenseGroup(firstRange, secondRange) {
19 return false
20 }
21 return firstRange.location[versionGroup] > secondRange.location[versionGroup]
22 }
23
24 // compareLT returns true if the first range is less than the second range within the same license group; otherwise, false.
25 func compareLT(first *node, second *node) bool {
26 if !first.isLicense() || !second.isLicense() {
27 return false
28 }
29 firstRange := getLicenseRange(*first.license())
30 secondRange := getLicenseRange(*second.license())
31
32 if !sameLicenseGroup(firstRange, secondRange) {
33 return false
34 }
35 return firstRange.location[versionGroup] < secondRange.location[versionGroup]
36 }
37
38 // compareEQ returns true if the first and second range are the same range within the same license group; otherwise, false.
39 func compareEQ(first *node, second *node) bool {
40 if !first.isLicense() || !second.isLicense() {
41 return false
42 }
43 if first.lic.license == second.lic.license {
44 return true
45 }
46
47 firstRange := getLicenseRange(*first.license())
48 secondRange := getLicenseRange(*second.license())
49
50 if !sameLicenseGroup(firstRange, secondRange) {
51 return false
52 }
53 return firstRange.location[versionGroup] == secondRange.location[versionGroup]
54 }
55
56 // sameLicenseGroup returns false if either license isn't in a range or the two ranges are
57 // not in the same license group (e.g. group GPL != group Apache); otherwise, true
58 func sameLicenseGroup(firstRange *licenseRange, secondRange *licenseRange) bool {
59 if firstRange == nil || secondRange == nil || firstRange.location[licenseGroup] != secondRange.location[licenseGroup] {
60 return false
61 }
62 return true
63 }