ParsePattern parses a gitignore pattern string into the Pattern structure.
(p string, domain []string)
| 49 | |
| 50 | // ParsePattern parses a gitignore pattern string into the Pattern structure. |
| 51 | func 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 | |
| 78 | func (p *pattern) Match(path []string, isDir bool) MatchResult { |
| 79 | if len(path) <= len(p.domain) { |
no outgoing calls
searching dependent graphs…