tartrazine/common.go

57 lines
1.6 KiB
Go
Raw Normal View History

2016-07-13 17:05:09 +00:00
package slinguist
2016-07-18 14:20:12 +00:00
const OtherLanguage = "Other"
var (
2016-08-02 08:38:14 +00:00
ExtensionsByLanguage map[string][]string
2016-07-18 14:20:12 +00:00
ignoredExtensions = map[string]bool{
".asc": true, ".cgi": true, ".fcgi": true, ".gml": true, ".fx": true,
".vhost": true,
}
auxiliaryLanguages = map[string]bool{
"Other": true, "XML": true, "YAML": true, "TOML": true, "INI": true,
"JSON": true, "TeX": true, "Public Key": true, "AsciiDoc": true,
"AGS Script": true, "VimL": true, "Diff": true, "CMake": true, "fish": true,
"Awk": true, "Graphviz (DOT)": true, "Markdown": true, "desktop": true,
"XSLT": true, "SQL": true, "RMarkdown": true, "IRC log": true,
"reStructuredText": true, "Twig": true, "CSS": true, "Batchfile": true,
"Text": true, "HTML+ERB": true, "HTML": true, "Gettext Catalog": true,
"Smarty": true, "Raw token data": true,
}
)
2016-07-13 17:05:09 +00:00
func init() {
2016-07-18 14:20:12 +00:00
for l, _ := range ignoredExtensions {
languagesByExtension[l] = []string{OtherLanguage}
2016-07-14 16:12:12 +00:00
}
2016-08-02 08:38:14 +00:00
ExtensionsByLanguage = reverseStringListMap(languagesByExtension)
2016-07-13 17:05:09 +00:00
}
2016-07-18 14:20:12 +00:00
// GetLanguageExtensions returns the different extensions being used by the
// language.
2016-07-13 17:05:09 +00:00
func GetLanguageExtensions(language string) []string {
2016-08-02 08:38:14 +00:00
return ExtensionsByLanguage[language]
2016-07-13 17:05:09 +00:00
}
2016-07-18 14:20:12 +00:00
// GetLanguage return the Language for a given filename and file content.
func GetLanguage(filename string, content []byte) string {
if lang, safe := GetLanguageByExtension(filename); safe {
return lang
}
2016-07-13 17:05:09 +00:00
2016-07-18 14:20:12 +00:00
lang, _ := GetLanguageByContent(filename, content)
return lang
}
func reverseStringListMap(i map[string][]string) (o map[string][]string) {
o = map[string][]string{}
for key, set := range i {
2016-07-13 17:05:09 +00:00
for _, value := range set {
2016-07-18 14:20:12 +00:00
o[value] = append(o[value], key)
2016-07-13 17:05:09 +00:00
}
}
2016-07-18 14:20:12 +00:00
2016-07-13 17:05:09 +00:00
return
}