GitignoreParser.parse constructor
GitignoreParser.parse(
- String content
Parses gitignore content (the text of a .gitignore file).
Implementation
factory GitignoreParser.parse(String content) {
final rules = <_GitignoreRule>[];
for (var line in content.split('\n')) {
line = line.trimRight();
if (line.isEmpty || line.startsWith('#')) continue;
final negated = line.startsWith('!');
if (negated) line = line.substring(1);
final dirOnly = line.endsWith('/');
if (dirOnly) line = line.substring(0, line.length - 1);
rules.add(
_GitignoreRule(
pattern: GlobMatcher.compile(line),
negated: negated,
directoryOnly: dirOnly,
),
);
}
return GitignoreParser._(rules);
}