MCPcopy Create free account
hub / github.com/go-task/task / ParsePattern

Function ParsePattern

internal/gitignore/pattern.go:51–76  ·  view source on GitHub ↗

ParsePattern parses a gitignore pattern string into the Pattern structure.

(p string, domain []string)

Source from the content-addressed store, hash-verified

49
50// ParsePattern parses a gitignore pattern string into the Pattern structure.
51func ParsePattern(p string, domain []string) Pattern {
52 // storing domain, copy it to ensure it isn't changed externally
53 domain = append([]string(nil), domain...)
54 res := pattern{domain: domain}
55
56 if strings.HasPrefix(p, inclusionPrefix) {
57 res.inclusion = true
58 p = p[1:]
59 }
60
61 if !strings.HasSuffix(p, "\\ ") {
62 p = strings.TrimRight(p, " ")
63 }
64
65 if strings.HasSuffix(p, patternDirSep) {
66 res.dirOnly = true
67 p = p[:len(p)-1]
68 }
69
70 if strings.Contains(p, patternDirSep) {
71 res.isGlob = true
72 }
73
74 res.pattern = strings.Split(p, patternDirSep)
75 return &res
76}
77
78func (p *pattern) Match(path []string, isDir bool) MatchResult {
79 if len(path) <= len(p.domain) {

Callers 3

filterGitignoredFunction · 0.92
TestMatcher_MatchFunction · 0.85
TestParsePattern_MatchFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestMatcher_MatchFunction · 0.68
TestParsePattern_MatchFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…