mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-21 18:01:11 +00:00
Update go-enry dependency to v2.6.0 (#13861)
This commit is contained in:
parent
8561f26695
commit
4a510e08e4
18 changed files with 32345 additions and 25977 deletions
61
vendor/github.com/go-enry/go-enry/v2/common.go
generated
vendored
61
vendor/github.com/go-enry/go-enry/v2/common.go
generated
vendored
|
@ -22,6 +22,8 @@ var DefaultStrategies = []Strategy{
|
|||
GetLanguagesByFilename,
|
||||
GetLanguagesByShebang,
|
||||
GetLanguagesByExtension,
|
||||
GetLanguagesByXML,
|
||||
GetLanguagesByManpage,
|
||||
GetLanguagesByContent,
|
||||
GetLanguagesByClassifier,
|
||||
}
|
||||
|
@ -328,15 +330,23 @@ func getInterpreter(data []byte) (interpreter string) {
|
|||
return
|
||||
}
|
||||
|
||||
func getFirstLine(content []byte) []byte {
|
||||
nlpos := bytes.IndexByte(content, '\n')
|
||||
if nlpos < 0 {
|
||||
return content
|
||||
func getFirstLines(content []byte, count int) []byte {
|
||||
nlpos := -1
|
||||
for ; count > 0; count-- {
|
||||
pos := bytes.IndexByte(content[nlpos+1:], '\n')
|
||||
if pos < 0 {
|
||||
return content
|
||||
}
|
||||
nlpos += pos + 1
|
||||
}
|
||||
|
||||
return content[:nlpos]
|
||||
}
|
||||
|
||||
func getFirstLine(content []byte) []byte {
|
||||
return getFirstLines(content, 1)
|
||||
}
|
||||
|
||||
func hasShebang(line []byte) bool {
|
||||
const shebang = `#!`
|
||||
prefix := []byte(shebang)
|
||||
|
@ -383,6 +393,49 @@ func GetLanguagesByExtension(filename string, _ []byte, _ []string) []string {
|
|||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
manpageExtension = regex.MustCompile(`\.(?:[1-9](?:[a-z_]+[a-z_0-9]*)?|0p|n|man|mdoc)(?:\.in)?$`)
|
||||
)
|
||||
|
||||
// GetLanguagesByManpage returns a slice of possible manpage languages for the given filename.
|
||||
// It complies with the signature to be a Strategy type.
|
||||
func GetLanguagesByManpage(filename string, _ []byte, _ []string) []string {
|
||||
filename = strings.ToLower(filename)
|
||||
|
||||
// Check if matches Roff man page filenames
|
||||
if manpageExtension.Match([]byte(filename)) {
|
||||
return []string{
|
||||
"Roff Manpage",
|
||||
"Roff",
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
xmlHeader = regex.MustCompile(`<?xml version=`)
|
||||
)
|
||||
|
||||
// GetLanguagesByXML returns a slice of possible XML language for the given filename.
|
||||
// It complies with the signature to be a Strategy type.
|
||||
func GetLanguagesByXML(_ string, content []byte, candidates []string) []string {
|
||||
if len(candidates) > 0 {
|
||||
return candidates
|
||||
}
|
||||
|
||||
header := getFirstLines(content, 2)
|
||||
|
||||
// Check if contains XML header
|
||||
if xmlHeader.Match(header) {
|
||||
return []string{
|
||||
"XML",
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getDotIndexes(filename string) []int {
|
||||
dots := make([]int, 0, 2)
|
||||
for i, letter := range filename {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue