ParsePattern parses a gitignore pattern string into the Pattern structure.
(p string, domain []string)
| 39 | |
| 40 | // ParsePattern parses a gitignore pattern string into the Pattern structure. |
| 41 | func ParsePattern(p string, domain []string) Pattern { |
| 42 | // storing domain, copy it to ensure it isn't changed externally |
| 43 | domain = append([]string(nil), domain...) |
| 44 | res := pattern{domain: domain} |
| 45 | |
| 46 | if strings.HasPrefix(p, inclusionPrefix) { |
| 47 | res.inclusion = true |
| 48 | p = p[1:] |
| 49 | } |
| 50 | |
| 51 | if !strings.HasSuffix(p, "\\ ") { |
| 52 | p = strings.TrimRight(p, " ") |
| 53 | } |
| 54 | |
| 55 | if strings.HasSuffix(p, patternDirSep) { |
| 56 | res.dirOnly = true |
| 57 | p = p[:len(p)-1] |
| 58 | } |
| 59 | |
| 60 | if strings.Contains(p, patternDirSep) { |
| 61 | res.isGlob = true |
| 62 | } |
| 63 | |
| 64 | res.pattern = strings.Split(p, patternDirSep) |
| 65 | return &res |
| 66 | } |
| 67 | |
| 68 | func (p *pattern) Match(path []string, isDir bool) MatchResult { |
| 69 | if len(path) <= len(p.domain) { |
searching dependent graphs…