Debian Codegraph @

spdxexp/license.go

raw symbols SCIP
1 package spdxexp
2
3 import (
4 "strings"
5
6 "github.com/github/go-spdx/v2/spdxexp/spdxlicenses"
7 )
8
9 // activeLicense returns true if the id is an active license.
10 func activeLicense(id string) (bool, string) {
11 return spdxlicenses.IsActiveLicense(id)
12 }
13
14 // ActiveLicense returns true if the id is an active license.
15 func ActiveLicense(id string) (bool, string) {
16 return activeLicense(id)
17 }
18
19 // deprecatedLicense returns true if the id is a deprecated license.
20 func deprecatedLicense(id string) (bool, string) {
21 return spdxlicenses.IsDeprecatedLicense(id)
22 }
23
24 // exceptionLicense returns true if the id is an exception license.
25 func exceptionLicense(id string) (bool, string) {
26 return spdxlicenses.IsException(id)
27 }
28
29 const (
30 licenseGroup uint8 = iota
31 versionGroup
32 licenseIndex
33 )
34
35 type licenseRange struct {
36 licenses []string
37 location map[uint8]int // licenseGroup, versionGroup, licenseIndex
38 }
39
40 // getLicenseRange returns a range of licenses from licenseRanges
41 func getLicenseRange(id string) *licenseRange {
42 simpleID := simplifyLicense(id)
43 allRanges := spdxlicenses.LicenseRanges()
44 for i, licenseGrp := range allRanges {
45 for j, versionGrp := range licenseGrp {
46 for k, license := range versionGrp {
47 if simpleID == license {
48 location := map[uint8]int{
49 licenseGroup: i,
50 versionGroup: j,
51 licenseIndex: k,
52 }
53 return &licenseRange{
54 licenses: versionGrp,
55 location: location,
56 }
57 }
58 }
59 }
60 }
61 return nil
62 }
63
64 func simplifyLicense(id string) string {
65 if strings.HasSuffix(id, "-or-later") {
66 return id[0 : len(id)-9]
67 }
68 return id
69 }