Beispiel #1
0
        public static PathPattern Create([NotNull] string pattern)
        {
            Guard.NotNull(pattern, nameof(pattern));

            pattern = pattern.TrimEnd();

            if (string.IsNullOrWhiteSpace(pattern))
            {
                return(new PathPattern(EmptySequence.Default, null));
            }

            if (StartsWithPathSeparator(pattern) || StartsWithDriveLetter(pattern))
            {
                throw ErrorFactory.System.SearchPatternMustNotBeDriveOrUnc(nameof(pattern));
            }

            PathPattern root = null;

            foreach (string directoryPattern in pattern.Split(PathFacts.DirectorySeparatorChars).Reverse())
            {
                AssertDirectoryPatternIsValid(directoryPattern);

                Sequence sequence = ParsePattern(directoryPattern);

                if (root != null && SequenceContainsWildcards(sequence))
                {
                    throw ErrorFactory.System.FileOrDirectoryOrVolumeIsIncorrect();
                }

                root = new PathPattern(sequence, root);
            }

            // ReSharper disable once AssignNullToNotNullAttribute
            return(root);
        }
Beispiel #2
0
 public PathFilter([CanBeNull] string text, bool allowEmptyString)
 {
     if (allowEmptyString && text == string.Empty)
     {
         Text     = string.Empty;
         sequence = PathPattern.ParsePattern("*");
     }
     else
     {
         Text     = string.IsNullOrEmpty(text) ? "*.*" : text;
         sequence = PathPattern.ParsePattern(Text == "*.*" ? "*" : Text);
     }
 }
Beispiel #3
0
 private PathPattern([NotNull] Sequence root, [CanBeNull] PathPattern subPattern)
 {
     this.root  = root;
     SubPattern = subPattern;
 }