parse static method

IgnorePattern? parse(
  1. String pattern
)

Parses a gitignore-style pattern.

Returns null if the pattern is empty after normalization.

Implementation

static IgnorePattern? parse(String pattern) {
  var normalized = pattern;

  // Check if this is a directory-only pattern
  final isDirectoryOnly = normalized.endsWith('/');
  if (isDirectoryOnly) {
    normalized = normalized.substring(0, normalized.length - 1);
  }

  // Remove leading slash (anchors to root)
  if (normalized.startsWith('/')) {
    normalized = normalized.substring(1);
  }

  if (normalized.isEmpty) {
    return null;
  }

  // Check if pattern has path separator (requires path-based matching)
  final hasPathSeparator = normalized.contains('/');

  return IgnorePattern._(Glob(normalized), hasPathSeparator, isDirectoryOnly);
}