mirror of
https://github.com/anchore/syft
synced 2024-11-10 06:14:16 +00:00
42fa9e4965
this PR makes the following changes to update the underlying license model to have more expressive capabilities it also provides some guarantee's surrounding the license values themselves - Licenses are updated from string -> pkg.LicenseSet which contain pkg.License with the following fields: - original `Value` read by syft - If it's possible to construct licenses will always have a valid SPDX expression for downstream consumption - the above is run against a generated list of SPDX license ID to try and find the correct ID - SPDX concluded vs declared is added to the new struct - URL source for license is added to the new struct - Location source is added to the new struct to show where the expression was pulled from
61 lines
1.1 KiB
Go
61 lines
1.1 KiB
Go
package internal
|
|
|
|
import "sort"
|
|
|
|
// StringSet represents a set of string types.
|
|
type StringSet map[string]struct{}
|
|
|
|
// NewStringSet creates a new empty StringSet.
|
|
func NewStringSet(start ...string) StringSet {
|
|
ret := make(StringSet)
|
|
for _, s := range start {
|
|
ret.Add(s)
|
|
}
|
|
return ret
|
|
}
|
|
|
|
// Add a string to the set.
|
|
func (s StringSet) Add(i ...string) {
|
|
for _, str := range i {
|
|
s[str] = struct{}{}
|
|
}
|
|
}
|
|
|
|
// Remove a string from the set.
|
|
func (s StringSet) Remove(i string) {
|
|
delete(s, i)
|
|
}
|
|
|
|
// Contains indicates if the given string is contained within the set.
|
|
func (s StringSet) Contains(i string) bool {
|
|
_, ok := s[i]
|
|
return ok
|
|
}
|
|
|
|
// ToSlice returns a sorted slice of strings that are contained within the set.
|
|
func (s StringSet) ToSlice() []string {
|
|
ret := make([]string, len(s))
|
|
idx := 0
|
|
for v := range s {
|
|
ret[idx] = v
|
|
idx++
|
|
}
|
|
sort.Strings(ret)
|
|
return ret
|
|
}
|
|
|
|
func (s StringSet) Equals(o StringSet) bool {
|
|
if len(s) != len(o) {
|
|
return false
|
|
}
|
|
for k := range s {
|
|
if !o.Contains(k) {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
func (s StringSet) Empty() bool {
|
|
return len(s) < 1
|
|
}
|