mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-06-18 22:23:07 -03:00
data: replace substring package with regex package
This commit is contained in:
17
utils.go
17
utils.go
@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/go-enry/go-enry/v2/data"
|
||||
"github.com/go-enry/go-enry/v2/regex"
|
||||
)
|
||||
|
||||
const binSniffLen = 8000
|
||||
@ -46,7 +47,7 @@ func GetMIMEType(path string, language string) string {
|
||||
|
||||
// IsDocumentation returns whether or not path is a documentation path.
|
||||
func IsDocumentation(path string) bool {
|
||||
return data.DocumentationMatchers.Match(path)
|
||||
return matchRegexSlice(data.DocumentationMatchers, path)
|
||||
}
|
||||
|
||||
// IsDotFile returns whether or not path has dot as a prefix.
|
||||
@ -57,12 +58,12 @@ func IsDotFile(path string) bool {
|
||||
|
||||
// IsVendor returns whether or not path is a vendor path.
|
||||
func IsVendor(path string) bool {
|
||||
return data.VendorMatchers.Match(path)
|
||||
return matchRegexSlice(data.VendorMatchers, path)
|
||||
}
|
||||
|
||||
// IsTest returns whether or not path is a test path.
|
||||
func IsTest(path string) bool {
|
||||
return data.TestMatchers.Match(path)
|
||||
return matchRegexSlice(data.TestMatchers, path)
|
||||
}
|
||||
|
||||
// IsBinary detects if data is a binary value based on:
|
||||
@ -91,3 +92,13 @@ func GetColor(language string) string {
|
||||
|
||||
return "#cccccc"
|
||||
}
|
||||
|
||||
func matchRegexSlice(exprs []regex.EnryRegexp, str string) bool {
|
||||
for _, expr := range exprs {
|
||||
if expr.MatchString(str) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
Reference in New Issue
Block a user