Source File
license.go
Belonging Package
github.com/google/licensecheck/old
package old
import (
)
func ( []License) *Checker {
:= &Checker{
licenses: make([]license, 0, len()),
urls: make(map[string]string),
dict: make(map[string]int32),
index: make(map[phrase][]indexEntry),
}
for , := range {
if .Text != "" {
:= len(.licenses)
.licenses = .licenses[:+1]
:= &.licenses[]
.name = .Name
.typ = licenseType(.name)
.text = .Text
.doc = .normalize([]byte(.text), true)
.updateIndex(int32(), .doc.words)
}
if .URL != "" {
.urls[.URL] = .Name
}
}
return
}
var builtin *Checker
var builtinList []License
return append([]License{}, builtinList...)
}
:= make([]bool, len())
:= float64(.Threshold)
if <= 0 {
= float64(defaults.Threshold)
}
for := range {
if [].Percent < {
[] = true
}
}
for := range {
if [] {
continue
}
:= &[]
:= .Percent * float64(.End-.Start)
for := range {
if [] || == {
continue
}
:= &[]
if .overlaps() {
:=
if > .Percent*float64(.End-.Start) {
=
}
[] = true
}
}
}
:= [:0]
for := range {
if ![] {
= append(, [])
}
}
=
:= .percent()
.toByteOffsets(, )
return Coverage{
Percent: ,
Match: ,
}, len() > 0
}
func ( *document) ( []Match) {
sort.Slice(, func(, int) bool {
:= &[]
:= &[]
if .Start != .Start {
return .Start < .Start
}
return .Name < .Name
})
}
func ( *document) ( int) int {
for , := range .byteOff {
if int() >= {
return
}
}
return len(.words)
}
:= int(.byteOff[-1])
for < len(.text) {
, := utf8.DecodeRune(.text[:])
if !isWordChar() {
break
}
+=
}
return
}
if < +3 {
continue
}
:= .endWordToEndByte(, )
:= urlRE.FindAllIndex(.text[:], -1)
if len() == 0 {
continue
}
for , := range {
, := [0]+, [1]+
if , := .licenseURL(string(.text[:])); {
= append(, Match{
Name: ,
Type: licenseType(),
Percent: 100.0, // 100% of Start:End is a license URL.
Start: .wordOffset(),
End: .wordOffset(),
IsURL: true,
})
}
}
}
return
}
= strings.TrimPrefix(, "http://")
= strings.TrimPrefix(, "https://")
= strings.TrimSuffix(, "/")
= strings.TrimSuffix(, "/legalcode") // Common for CC licenses.
= strings.ToLower()
, := .urls[]
if {
return , true
}
if == 0 {
return 0
func ( *document) ( []Match, int) int {
:= []
if !.IsURL {
return .End
}
if == len()-1 {
return len(.words)
}
:= [+1]
if !.IsURL {
return .Start
}
return (.End + .Start) / 2
}
func ( *license, submatch) Match {
var Match
.Name = .name
.Type = .typ
.Percent = 100 * float64(.matched) / float64(len(.doc.words))
.Start = .start
.End = .Start + (.end - .start)
return
}
var phrase
:=
:= +
const = 70
if := []; >= 0 {
:= &[]
:= .Slop
if .licenseEnd < len(.doc.words) && .doc.words[.licenseEnd] == blankID {
=
}
if .end+ >= && >= .licenseEnd {
if == {
.matched++ // matched the blank
}
.end =
.matched +=
.licenseEnd = +
continue
}
}
=
-= 2
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |