2017-02-26 01:02:39 +03:00
|
|
|
package highlight
|
|
|
|
|
2017-05-02 17:30:27 +03:00
|
|
|
import "regexp"
|
|
|
|
|
2017-10-01 19:42:23 +03:00
|
|
|
// MatchFiletype will use the list of syntax definitions provided and the filename and first line of the file
|
2017-03-28 02:35:28 +03:00
|
|
|
// to determine the filetype of the file
|
|
|
|
// It will return the corresponding syntax definition for the filetype
|
2017-05-02 17:30:27 +03:00
|
|
|
func MatchFiletype(ftdetect [2]*regexp.Regexp, filename string, firstLine []byte) bool {
|
2019-12-29 06:27:44 +03:00
|
|
|
if ftdetect[0] != nil && ftdetect[0].MatchString(filename) {
|
2017-05-03 18:04:56 +03:00
|
|
|
return true
|
|
|
|
}
|
2017-05-02 17:30:27 +03:00
|
|
|
|
|
|
|
if ftdetect[1] != nil {
|
|
|
|
return ftdetect[1].Match(firstLine)
|
2017-02-26 01:02:39 +03:00
|
|
|
}
|
|
|
|
|
2017-05-02 17:30:27 +03:00
|
|
|
return false
|
2017-02-26 01:02:39 +03:00
|
|
|
}
|