public Glob(string pattern, GlobOptions options = GlobOptions.None) { this.Pattern = pattern; _caseSensitive = !options.HasFlag(GlobOptions.CaseInsensitive); _matchFilenameOnly = !options.HasFlag(GlobOptions.MatchFullPath); if (options.HasFlag(GlobOptions.Compiled)) { this.Compile(); } }
public Glob(string pattern, GlobOptions options = GlobOptions.None) { this.Pattern = pattern; if (options.HasFlag(GlobOptions.Compiled)) { this.Compile(); } }
public Glob(string pattern, GlobOptions options = GlobOptions.None) { this.Pattern = pattern; if(options.HasFlag(GlobOptions.Compiled)) { this.Compile(); } }
public static bool TryParse(ReadOnlySpan <char> pattern, GlobOptions options, [NotNullWhen(true)] out Glob?result, [NotNullWhen(false)] out string?errorMessage) { result = null; if (pattern.IsEmpty) { errorMessage = "The pattern is empty"; return(false); } var ignoreCase = options.HasFlag(GlobOptions.IgnoreCase); var exclude = false; var segments = new List <Segment>(); List <Segment>? subSegments = null; List <string>? setSubsegment = null; List <CharacterRange>?rangeSubsegment = null; char? rangeStart = null; var rangeInverse = false; var escape = false; var parserContext = GlobParserContext.Segment; Span <char> sbSpan = stackalloc char[128]; var currentLiteral = new ValueStringBuilder(sbSpan); try { for (var i = 0; i < pattern.Length; i++) { var c = pattern[i]; if (escape) { currentLiteral.Append(c); escape = false; continue; } if (c == '!' && i == 0) { exclude = true; continue; } if (parserContext == GlobParserContext.Segment) { if (c == '/') { FinishSegment(segments, ref subSegments, ref currentLiteral, ignoreCase); continue; } else if (c == '.') { if (subSegments == null && currentLiteral.Length == 0) { if (EndOfSegmentEqual(pattern[i..], ".."))
public static IEnumerable <FileSystemInfo> FilesAndDirectories(DirectoryInfo workingDirectory, string pattern, GlobOptions options) => workingDirectory.Traverse(pattern, !options.HasFlag(GlobOptions.CaseInsensitive), true, true);
public static IEnumerable <DirectoryInfo> Directories(DirectoryInfo workingDirectory, string pattern, GlobOptions options) => workingDirectory .Traverse(pattern, !options.HasFlag(GlobOptions.CaseInsensitive), false, true) .OfType <DirectoryInfo>();