gopkg.in/alecthomas/gometalinter.v3@v3.0.0/_linters/src/github.com/client9/misspell/ignore/parse.go (about)

     1  package ignore
     2  
     3  import (
     4  	"bytes"
     5  )
     6  
     7  // Parse reads in a gitignore file and returns a Matcher
     8  func Parse(src []byte) (Matcher, error) {
     9  	matchers := []Matcher{}
    10  	lines := bytes.Split(src, []byte{'\n'})
    11  	for _, line := range lines {
    12  		if len(line) == 0 || len(bytes.TrimSpace(line)) == 0 {
    13  			continue
    14  		}
    15  
    16  		if line[0] == '#' {
    17  			continue
    18  		}
    19  
    20  		// TODO: line starts with '!'
    21  		// TODO: line ends with '\ '
    22  
    23  		// if starts with \# or \! then escaped
    24  		if len(line) > 1 && line[0] == '\\' && (line[1] == '#' || line[1] == '!') {
    25  			line = line[1:]
    26  		}
    27  
    28  		m, err := NewGlobMatch(line)
    29  		if err != nil {
    30  			return nil, err
    31  		}
    32  		matchers = append(matchers, m)
    33  	}
    34  	return NewMultiMatch(matchers), nil
    35  }