@@ -8,53 +8,20 @@ import (
88 "gopkg.in/src-d/enry.v1/data"
99)
1010
11- var (
12- auxiliaryLanguages = map [string ]bool {
13- "Other" : true , "XML" : true , "YAML" : true , "TOML" : true , "INI" : true ,
14- "JSON" : true , "TeX" : true , "Public Key" : true , "AsciiDoc" : true ,
15- "AGS Script" : true , "VimL" : true , "Diff" : true , "CMake" : true , "fish" : true ,
16- "Awk" : true , "Graphviz (DOT)" : true , "Markdown" : true , "desktop" : true ,
17- "XSLT" : true , "SQL" : true , "RMarkdown" : true , "IRC log" : true ,
18- "reStructuredText" : true , "Twig" : true , "CSS" : true , "Batchfile" : true ,
19- "Text" : true , "HTML+ERB" : true , "HTML" : true , "Gettext Catalog" : true ,
20- "Smarty" : true , "Raw token data" : true ,
21- }
11+ const binSniffLen = 8000
2212
23- configurationLanguages = map [string ]bool {
24- "XML" : true , "JSON" : true , "TOML" : true , "YAML" : true , "INI" : true , "SQL" : true ,
25- }
26- )
27-
28- // IsAuxiliaryLanguage returns whether or not lang is an auxiliary language.
29- func IsAuxiliaryLanguage (lang string ) bool {
30- _ , ok := auxiliaryLanguages [lang ]
31- return ok
13+ var configurationLanguages = map [string ]bool {
14+ "XML" : true , "JSON" : true , "TOML" : true , "YAML" : true , "INI" : true , "SQL" : true ,
3215}
3316
34- // IsConfiguration returns whether or not path is using a configuration language .
17+ // IsConfiguration tells if filename is in one of the configuration languages .
3518func IsConfiguration (path string ) bool {
3619 language , _ := GetLanguageByExtension (path )
3720 _ , is := configurationLanguages [language ]
3821 return is
3922}
4023
41- // IsDotFile returns whether or not path has dot as a prefix.
42- func IsDotFile (path string ) bool {
43- path = filepath .Clean (path )
44- base := filepath .Base (path )
45- return strings .HasPrefix (base , "." ) && base != "." && base != ".."
46- }
47-
48- // IsVendor returns whether or not path is a vendor path.
49- func IsVendor (path string ) bool {
50- return data .VendorMatchers .Match (path )
51- }
52-
53- // IsDocumentation returns whether or not path is a documentation path.
54- func IsDocumentation (path string ) bool {
55- return data .DocumentationMatchers .Match (path )
56- }
57-
24+ // IsImage tells if a given file is an image (PNG, JPEG or GIF format).
5825func IsImage (path string ) bool {
5926 extension := filepath .Ext (path )
6027 if extension == ".png" || extension == ".jpg" || extension == ".jpeg" || extension == ".gif" {
@@ -64,7 +31,8 @@ func IsImage(path string) bool {
6431 return false
6532}
6633
67- func GetMimeType (path string , language string ) string {
34+ // GetMIMEType returns a MIME type of a given file based on its languages.
35+ func GetMIMEType (path string , language string ) string {
6836 if mime , ok := data .LanguagesMime [language ]; ok {
6937 return mime
7038 }
@@ -76,13 +44,27 @@ func GetMimeType(path string, language string) string {
7644 return "text/plain"
7745}
7846
79- const sniffLen = 8000
47+ // IsDocumentation returns whether or not path is a documentation path.
48+ func IsDocumentation (path string ) bool {
49+ return data .DocumentationMatchers .Match (path )
50+ }
51+
52+ // IsDotFile returns whether or not path has dot as a prefix.
53+ func IsDotFile (path string ) bool {
54+ base := filepath .Base (filepath .Clean (path ))
55+ return strings .HasPrefix (base , "." ) && base != "."
56+ }
57+
58+ // IsVendor returns whether or not path is a vendor path.
59+ func IsVendor (path string ) bool {
60+ return data .VendorMatchers .Match (path )
61+ }
8062
8163// IsBinary detects if data is a binary value based on:
8264// http://git.kernel.org/cgit/git/git.git/tree/xdiff-interface.c?id=HEAD#n198
8365func IsBinary (data []byte ) bool {
84- if len (data ) > sniffLen {
85- data = data [:sniffLen ]
66+ if len (data ) > binSniffLen {
67+ data = data [:binSniffLen ]
8668 }
8769
8870 if bytes .IndexByte (data , byte (0 )) == - 1 {
@@ -91,17 +73,3 @@ func IsBinary(data []byte) bool {
9173
9274 return true
9375}
94-
95- // FileCount type stores language name and count of files belonging to the
96- // language.
97- type FileCount struct {
98- Name string
99- Count int
100- }
101-
102- // FileCountList type is a list of FileCounts.
103- type FileCountList []FileCount
104-
105- func (fcl FileCountList ) Len () int { return len (fcl ) }
106- func (fcl FileCountList ) Less (i , j int ) bool { return fcl [i ].Count < fcl [j ].Count }
107- func (fcl FileCountList ) Swap (i , j int ) { fcl [i ], fcl [j ] = fcl [j ], fcl [i ] }
0 commit comments