File: index_scan_patterns.go

package info (click to toggle)
golang-github-monochromegane-go-gitignore 0.0~git20200626.205db1a-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 108 kB
  • sloc: makefile: 2
file content (35 lines) | stat: -rw-r--r-- 705 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package gitignore

import "strings"

type indexScanPatterns struct {
	absolute depthPatternHolder
	relative depthPatternHolder
}

func newIndexScanPatterns() *indexScanPatterns {
	return &indexScanPatterns{
		absolute: newDepthPatternHolder(asc),
		relative: newDepthPatternHolder(desc),
	}
}

func (ps *indexScanPatterns) add(pattern string) {
	if strings.HasPrefix(pattern, "/") {
		ps.absolute.add(pattern)
	} else {
		ps.relative.add(pattern)
	}
}

func (ps indexScanPatterns) match(path string, isDir bool) bool {
	if ps.absolute.match(path, isDir) {
		return true
	}
	return ps.relative.match(path, isDir)
}

type scanStrategy interface {
	add(pattern string)
	match(path string, isDir bool) bool
}