Copyright 2019 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

package frontend

import (
	
	
	
	

	
	
	
)
License contains information used for a single license section.
LicensesDetails contains license information for a package or module.
type LicensesDetails struct {
	Licenses []License
}
LicenseMetadata contains license metadata that is used in the package header.
fetchLicensesDetails fetches license data for the package version specified by path and version from the database and returns a LicensesDetails.
transformLicenses transforms licenses.License into a License by adding an anchor field.
func (,  string,  []*licenses.License) []License {
	 := make([]License, len())
	var  []string
	for ,  := range  {
		 = append(, .FilePath)
	}
	 := licenseAnchors()
	for ,  := range  {
		.Contents = bytes.ReplaceAll(.Contents, []byte("\r"), nil)
		[] = License{
			Anchor:  [],
			License: ,
			Source:  fileSource(, , .FilePath),
		}
	}
	return 
}
transformLicenseMetadata transforms licenses.Metadata into a LicenseMetadata by adding an anchor field.
func ( []*licenses.Metadata) []LicenseMetadata {
	var  []LicenseMetadata
	var  []string
	for ,  := range  {
		 = append(, .FilePath)
	}
	 := licenseAnchors()
	for ,  := range  {
		 := []
		for ,  := range .Types {
			 = append(, LicenseMetadata{
				Type:   ,
				Anchor: ,
			})
		}
	}
	return 
}
licenseAnchors returns anchors (HTML identifiers) for all the paths, in the same order. If the paths are unique, it ensures that the resulting anchors are unique. The argument is modified.
Remember the original index of each path.
	 := map[string]int{}
	for ,  := range  {
		[] = 
Pick a canonical order for the paths, so we assign the same anchors the same set of paths regardless of the order they're given to use.
	sort.Strings()
	 := make([]safehtml.Identifier, len())
	for ,  := range  {
		[[]] = safehtml.IdentifierFromConstantPrefix("lic", strconv.Itoa())
	}
	return