slinguist

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2017 License: MIT Imports: 6 Imported by: 0

README

simple-linguist GoDoc Build Status

File language detector and toolbox to ignore binary or vendored files. simple-linguist, is our port to Go of the original linguist Ruby library, with fewer precision in arcane languages but with an improved performance of 100x.

Installation

The recommended way to install simple-linguist

go get gopkg.in/src-d/simple-linguist.v1/...

Examples

lang, _ := GetLanguageByExtension("foo.go")
fmt.Println(lang)
// result: Go

lang, _ = GetLanguageByContent("foo.m", "<matlab-code>")
fmt.Println(lang)
// result: Matlab

lang, _ = GetLanguageByContent("bar.m", "<pbjective-c-code>")
fmt.Println(lang)
// result: Objective-C

License

MIT, see LICENSE

Documentation

Index

Constants

View Source
const OtherLanguage = "Other"

Variables

View Source
var (
	ExtensionsByLanguage map[string][]string
)

Functions

func GetLanguage

func GetLanguage(filename string, content []byte) string

GetLanguage return the Language for a given filename and file content.

func GetLanguageByAlias

func GetLanguageByAlias(alias string) (lang string)

GetLanguageByAlias returns the language related to the given alias or Otherlanguage otherwise.

func GetLanguageByContent

func GetLanguageByContent(filename string, content []byte) (lang string, safe bool)

func GetLanguageByEmacsModeline

func GetLanguageByEmacsModeline(content []byte) (lang string)

GetLanguageByEmacsModeline detecs if the content has a emacs modeline and try to get a language basing on alias. If couldn't retrieve a valid language, it returns OtherLanguage.

func GetLanguageByExtension

func GetLanguageByExtension(filename string) (lang string, safe bool)

func GetLanguageByFilename

func GetLanguageByFilename(filename string) (lang string, safe bool)

func GetLanguageByModeline

func GetLanguageByModeline(content []byte) (lang string, safe bool)

GetLanguageByModeline returns the language of the given content looking for the modeline, and safe to indicate the sureness of returned language.

func GetLanguageByShebang

func GetLanguageByShebang(content []byte) (lang string, safe bool)

GetLanguageByShebang returns the language of the given content looking for the shebang line, and safe to indicate the sureness of returned language.

func GetLanguageByVimModeline

func GetLanguageByVimModeline(content []byte) (lang string)

GetLanguageByVimModeline detecs if the content has a vim modeline and try to get a language basing on alias. If couldn't retrieve a valid language, it returns OtherLanguage.

func GetLanguageExtensions

func GetLanguageExtensions(language string) []string

GetLanguageExtensions returns the different extensions being used by the language.

func IsAuxiliaryLanguage

func IsAuxiliaryLanguage(lang string) bool

func IsBinary

func IsBinary(data []byte) bool

IsBinary detects if data is a binary value based on: http://git.kernel.org/cgit/git/git.git/tree/xdiff-interface.c?id=HEAD#n198

func IsConfiguration

func IsConfiguration(path string) bool

func IsDocumentation

func IsDocumentation(path string) bool

func IsDotFile

func IsDotFile(path string) bool

func IsVendor

func IsVendor(path string) bool

Types

type Type

type Type int
const (
	// Language's type. Either data, programming, markup, prose, or unknown.
	Unknown Type = iota
	Data
	Programming
	Markup
	Prose
)

func GetLanguageType

func GetLanguageType(language string) (langType Type)

GetLanguageType returns the given language's type.

Directories

Path Synopsis
cli
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL