]> git.lizzy.rs Git - micro.git/blob - pkg/highlight/ftdetect.go
Merge pull request #1437 from serebit/patch-2
[micro.git] / pkg / highlight / ftdetect.go
1 package highlight
2
3 import "regexp"
4
5 // MatchFiletype will use the list of syntax definitions provided and the filename and first line of the file
6 // to determine the filetype of the file
7 // It will return the corresponding syntax definition for the filetype
8 func MatchFiletype(ftdetect [2]*regexp.Regexp, filename string, firstLine []byte) bool {
9         if ftdetect[0] != nil && ftdetect[0].MatchString(filename) {
10                 return true
11         }
12
13         if ftdetect[1] != nil {
14                 return ftdetect[1].Match(firstLine)
15         }
16
17         return false
18 }