Return the def object rather than the filetype string

This commit is contained in:
Zachary Yedidia
2017-02-15 18:37:00 -05:00
parent 33e77466e0
commit 0f34a2d8ba
+6 -4
View File
@@ -2,17 +2,19 @@ package highlight
import "bytes" import "bytes"
func DetectFiletype(defs []*Def, filename string, fileSrc []byte) string { func DetectFiletype(defs []*Def, filename string, fileSrc []byte) *Def {
firstLine := bytes.Split(fileSrc, []byte("\n"))[0] firstLine := bytes.Split(fileSrc, []byte("\n"))[0]
for _, d := range defs { for _, d := range defs {
if d.ftdetect[0].Match([]byte(filename)) { if d.ftdetect[0].Match([]byte(filename)) {
return d.ft return d
} }
if len(d.ftdetect) > 1 {
if d.ftdetect[1].Match(firstLine) { if d.ftdetect[1].Match(firstLine) {
return d.ft return d
}
} }
} }
return "Unknown" return nil
} }