gopkg.in/tools/godep.v45@v45.0.0-20151228215228-7e51f1a9c00c/license.go (about)

     1  package main
     2  
     3  import (
     4  	"strings"
     5  )
     6  
     7  // LicenseFilePrefix is a list of filename prefixes that indicate it
     8  //  might contain a software license
     9  var LicenseFilePrefix = []string{
    10  	"license",
    11  	"copying",
    12  	"unlicense",
    13  	"copyright",
    14  	"copyleft",
    15  }
    16  
    17  // LegalFileSubstring are substrings that indicate the file is likely
    18  // to contain some type of legal declaration.  "legal" is often used
    19  // that it might moved to LicenseFilePrefix
    20  var LegalFileSubstring = []string{
    21  	"legal",
    22  	"notice",
    23  	"disclaimer",
    24  	"patent",
    25  	"third-party",
    26  	"thirdparty",
    27  }
    28  
    29  // IsLicenseFile returns true if the filename might be contain a
    30  // software license
    31  func IsLicenseFile(filename string) bool {
    32  	lowerfile := strings.ToLower(filename)
    33  	for _, prefix := range LicenseFilePrefix {
    34  		if strings.HasPrefix(lowerfile, prefix) {
    35  			return true
    36  		}
    37  	}
    38  	return false
    39  }
    40  
    41  // IsLegalFile returns true if the file is likely to contain some type
    42  // of of legal declaration or licensing information
    43  func IsLegalFile(filename string) bool {
    44  	lowerfile := strings.ToLower(filename)
    45  	for _, prefix := range LicenseFilePrefix {
    46  		if strings.HasPrefix(lowerfile, prefix) {
    47  			return true
    48  		}
    49  	}
    50  	for _, substring := range LegalFileSubstring {
    51  		if strings.Index(lowerfile, substring) != -1 {
    52  			return true
    53  		}
    54  	}
    55  	return false
    56  }