Пример #1
0
    public override int MatchWorker(MatchKind kind, IPathComparer comparer, IList<BaseOperator> operators, int operatorIndex, string path, int pathIndex) {
      // If we are the last operation, don't match
      if (operatorIndex == operators.Count - 1)
        return -1;

      // If we reach the end of the "path", or we are not on a path separator, don't match
      if (pathIndex == path.Length || !FileNameMatching.IsPathSeparator(path[pathIndex]))
        return -1;

      pathIndex++;

      while (pathIndex < path.Length) {
        var result = Match(kind, comparer, operators, operatorIndex + 1, path, pathIndex);
        if (result == path.Length)
          return result;

        // Look for next path separator in path
        var nextPathIndex = path.IndexOf(Path.DirectorySeparatorChar, pathIndex, path.Length - pathIndex);
        if (nextPathIndex < 0)
          break;

        pathIndex = nextPathIndex + 1;
      }

      return -1;
    }
Пример #2
0
 public override int MatchWorker(MatchKind kind, IPathComparer comparer, IList<BaseOperator> operators, int operatorIndex, string path, int pathIndex)
 {
     var result = Match(kind, comparer, operators, operatorIndex + 1, path, pathIndex);
       if (kind == MatchKind.File && result == path.Length)
     return -1;
       return result;
 }
Пример #3
0
        public override int MatchWorker(MatchKind kind, IPathComparer comparer, IList <BaseOperator> operators, int operatorIndex, string path, int pathIndex)
        {
            // Heuristic: If last operator, there is a full match (since "*" at the
            // end matches everything)
            if (operatorIndex == operators.Count - 1)
            {
                if (path.IndexOf(Path.DirectorySeparatorChar, pathIndex) < 0)
                {
                    return(path.Length);
                }
                return(-1);
            }

            // Heuristic for "*[a-z]+":
            // * if we are matching a file name and
            // * if there are not path separators after "pathIndex" and
            // * if the only operator after us is "OpText"
            // * then we only need to check that path end with the text.
            if (kind == MatchKind.File)
            {
                if (path.IndexOf(Path.DirectorySeparatorChar, pathIndex) < 0)
                {
                    if (operatorIndex + 1 == operators.Count - 1)
                    {
                        var opText = operators[operatorIndex + 1] as OpText;
                        if (opText != null)
                        {
                            if (comparer.EndsWith(path, opText.Text))
                            {
                                var remaining = path.Length - pathIndex;
                                if (remaining >= opText.Text.Length)
                                {
                                    return(path.Length);
                                }
                            }
                            return(-1);
                        }
                    }
                }
            }

            // Full "*" semantics: any character except "/"
            for (var i = pathIndex; i < path.Length; i++)
            {
                // If we reach "/", move on to next operator
                if (FileNameMatching.IsPathSeparator(path[i]))
                {
                    return(Match(kind, comparer, operators, operatorIndex + 1, path, i));
                }

                var result = Match(kind, comparer, operators, operatorIndex + 1, path, i);
                if (result == path.Length)
                {
                    return(result);
                }
            }

            return(-1);
        }
Пример #4
0
 public override int MatchWorker(MatchKind kind, IPathComparer comparer, IList <BaseOperator> operators, int operatorIndex, string path, int pathIndex)
 {
     if (pathIndex < path.Length && path[pathIndex] == Path.DirectorySeparatorChar)
     {
         return(Match(kind, comparer, operators, operatorIndex + 1, path, pathIndex + 1));
     }
     return(-1);
 }
Пример #5
0
 private bool PrePassWontMatch(MatchKind kind, string path, IPathComparer comparer) {
   // Note: Use a "for" loop to avoid allocation with "Any"
   for (var index = 0; index < _prePassOperators.Length; index++) {
     if (_prePassOperators[index].PrePassWontMatch(kind, path, comparer))
       return true;
   }
   return false;
 }
Пример #6
0
    public override int MatchWorker(MatchKind kind, IPathComparer comparer, IList<BaseOperator> operators, int operatorIndex, string path, int pathIndex) {
      var len = _text.Length;

      if (comparer.Compare(_text, 0, path, pathIndex, len) != 0)
        return -1;

      return Match(kind, comparer, operators, operatorIndex + 1, path, pathIndex + len);
    }
Пример #7
0
    public bool MatchFileName(RelativePath relativePath, IPathComparer comparer) {
      var path = relativePath.Value;
      CheckPath(path);

      if (PrePassWontMatch(MatchKind.File, path, comparer))
        return false;

      var result = BaseOperator.Match(MatchKind.File, comparer, Operators, 0, path, 0);
      return IsMatch(path, result);
    }
Пример #8
0
        public override int MatchWorker(MatchKind kind, IPathComparer comparer, IList <BaseOperator> operators, int operatorIndex, string path, int pathIndex)
        {
            var result = Match(kind, comparer, operators, operatorIndex + 1, path, pathIndex);

            if (kind == MatchKind.File && result == path.Length)
            {
                return(-1);
            }
            return(result);
        }
Пример #9
0
        public bool MatchFileName(string path, IPathComparer comparer)
        {
            CheckPath(path);

              if (PrePassWontMatch(MatchKind.File, path, comparer))
            return false;

              var result = BaseOperator.Match(MatchKind.File, comparer, Operators, 0, path, 0);
              return IsMatch(path, result);
        }
Пример #10
0
        public override int MatchWorker(MatchKind kind, IPathComparer comparer, IList <BaseOperator> operators, int operatorIndex, string path, int pathIndex)
        {
            var len = _text.Length;

            if (String.Compare(_text, 0, path, pathIndex, len, comparer.Comparison) != 0)
            {
                return(-1);
            }

            return(Match(kind, comparer, operators, operatorIndex + 1, path, pathIndex + len));
        }
Пример #11
0
 private bool PrePassWontMatch(MatchKind kind, string path, IPathComparer comparer)
 {
     // Note: Use a "for" loop to avoid allocation with "Any"
     for (var index = 0; index < _prePassOperators.Length; index++)
     {
         if (_prePassOperators[index].PrePassWontMatch(kind, path, comparer))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #12
0
        public bool MatchFileName(string path, IPathComparer comparer)
        {
            CheckPath(path);

            if (PrePassWontMatch(MatchKind.File, path, comparer))
            {
                return(false);
            }

            var result = BaseOperator.Match(MatchKind.File, comparer, Operators, 0, path, 0);

            return(IsMatch(path, result));
        }
Пример #13
0
    /// <summary>
    /// Returns -1 if "path" does not conform to the pattern defined by "operators"
    /// Returns the index of the first character "path" which does not match the pattern.
    /// This means that if "index" == "path.Length", the whole path matches the pattern.
    /// </summary>
    public static int Match(MatchKind kind, IPathComparer comparer, IList<BaseOperator> operators, int operatorIndex, string path, int pathIndex) {
      if (operatorIndex > operators.Count)
        throw new ArgumentException("operator index outside of bounds.", "operatorIndex");

      if (pathIndex > path.Length)
        throw new ArgumentException("path index outside of bounds.", "pathIndex");

      // If we reach past the last operator, it means "we matched until this point".
      if (operatorIndex == operators.Count)
        return pathIndex;

      return operators[operatorIndex].MatchWorker(kind, comparer, operators, operatorIndex, path, pathIndex);
    }
Пример #14
0
    public bool MatchFileName(RelativePath relativePath, IPathComparer comparer) {
      if (relativePath.IsEmpty)
        throw new ArgumentNullException("relativePath");

      if (_fileExtensions.Contains(relativePath.Extension))
        return true;

      // Note: Use "for" loop to avoid allocation if using "Any()"
      for (var index = 0; index < _pathMatchers.Length; index++) {
        if (_pathMatchers[index].MatchFileName(relativePath, comparer))
          return true;
      }
      return false;
    }
Пример #15
0
    public override int MatchWorker(MatchKind kind, IPathComparer comparer, IList<BaseOperator> operators, int operatorIndex, string path, int pathIndex) {
      while (pathIndex < path.Length) {
        var result = Match(kind, comparer, operators, operatorIndex + 1, path, pathIndex);
        if (result >= 0)
          return result;

        // Look for next path separator in path
        var nextPathIndex = path.IndexOf(Path.DirectorySeparatorChar, pathIndex, path.Length - pathIndex);
        if (nextPathIndex < 0)
          break;
        pathIndex = nextPathIndex + 1;
      }

      return -1;
    }
Пример #16
0
        public bool MatchFileName(RelativePath relativePath, IPathComparer comparer)
        {
            var path = relativePath.Value;

            CheckPath(path);

            if (PrePassWontMatch(MatchKind.File, path, comparer))
            {
                return(false);
            }

            var result = BaseOperator.Match(MatchKind.File, comparer, Operators, 0, path, 0);

            return(IsMatch(path, result));
        }
        public bool MatchFileName(string path, IPathComparer comparer)
        {
            if (path == null)
            throw new ArgumentNullException("path");

              if (_fileExtensions.Contains(Path.GetExtension(path)))
            return true;

              // Note: Use "for" loop to avoid allocation if using "Any()"
              for (var index = 0; index < _pathMatchers.Length; index++) {
            if (_pathMatchers[index].MatchFileName(path, comparer))
              return true;
              }
              return false;
        }
Пример #18
0
    public override int MatchWorker(MatchKind kind, IPathComparer comparer, IList<BaseOperator> operators, int operatorIndex, string path, int pathIndex) {
      // Heuristic: If last operator, there is a full match (since "*" at the
      // end matches everything)
      if (operatorIndex == operators.Count - 1) {
        if (path.IndexOf(Path.DirectorySeparatorChar, pathIndex) < 0)
          return path.Length;
        return -1;
      }

      // Heuristic for "*[a-z]+":
      // * if we are matching a file name and
      // * if there are not path separators after "pathIndex" and
      // * if the only operator after us is "OpText"
      // * then we only need to check that path end with the text.
      if (kind == MatchKind.File) {
        if (path.IndexOf(Path.DirectorySeparatorChar, pathIndex) < 0) {
          if (operatorIndex + 1 == operators.Count - 1) {
            var opText = operators[operatorIndex + 1] as OpText;
            if (opText != null) {
              if (comparer.EndsWith(path, opText.Text)) {
                var remaining = path.Length - pathIndex;
                if (remaining >= opText.Text.Length)
                  return path.Length;
              }
              return -1;
            }
          }
        }
      }

      // Full "*" semantics: any character except "/"
      for (var i = pathIndex; i < path.Length; i++) {
        // If we reach "/", move on to next operator
        if (FileNameMatching.IsPathSeparator(path[i]))
          return Match(kind, comparer, operators, operatorIndex + 1, path, i);

        var result = Match(kind, comparer, operators, operatorIndex + 1, path, i);
        if (result == path.Length)
          return result;
      }

      return -1;
    }
Пример #19
0
        /// <summary>
        /// Returns -1 if "path" does not conform to the pattern defined by "operators"
        /// Returns the index of the first character "path" which does not match the pattern.
        /// This means that if "index" == "path.Length", the whole path matches the pattern.
        /// </summary>
        public static int Match(MatchKind kind, IPathComparer comparer, IList <BaseOperator> operators, int operatorIndex, string path, int pathIndex)
        {
            if (operatorIndex > operators.Count)
            {
                throw new ArgumentException("operator index outside of bounds.", "operatorIndex");
            }

            if (pathIndex > path.Length)
            {
                throw new ArgumentException("path index outside of bounds.", "pathIndex");
            }

            // If we reach past the last operator, it means "we matched until this point".
            if (operatorIndex == operators.Count)
            {
                return(pathIndex);
            }

            return(operators[operatorIndex].MatchWorker(kind, comparer, operators, operatorIndex, path, pathIndex));
        }
Пример #20
0
        public override int MatchWorker(MatchKind kind, IPathComparer comparer, IList <BaseOperator> operators, int operatorIndex, string path, int pathIndex)
        {
            while (pathIndex < path.Length)
            {
                var result = Match(kind, comparer, operators, operatorIndex + 1, path, pathIndex);
                if (result >= 0)
                {
                    return(result);
                }

                // Look for next path separator in path
                var nextPathIndex = path.IndexOf(Path.DirectorySeparatorChar, pathIndex, path.Length - pathIndex);
                if (nextPathIndex < 0)
                {
                    break;
                }
                pathIndex = nextPathIndex + 1;
            }

            return(-1);
        }
Пример #21
0
        public override int MatchWorker(MatchKind kind, IPathComparer comparer, IList<BaseOperator> operators, int operatorIndex, string path, int pathIndex)
        {
            // Heuristic: If last operator, there is a full match (since "*" at the end matches everything)
              if (operatorIndex == operators.Count - 1)
            return path.Length;

              // Heuristic:
              // * if we are matching a file name
              // * if there are not path separators after "pathIndex"
              // * if the only operator after us is "OpText", and
              // * then we only need to check that path end with the text.
              if (kind == MatchKind.File) {
            if (path.IndexOf(Path.DirectorySeparatorChar, pathIndex) < 0) {
              if (operatorIndex + 1 == operators.Count - 1) {
            var opText = operators[operatorIndex + 1] as OpText;
            if (opText != null) {
              if (path.EndsWith(opText.Text, comparer.Comparison)) {
                var remaining = path.Length - pathIndex;
                if (remaining >= opText.Text.Length)
                  return path.Length;
              }
              return -1;
            }
              }
            }
              }

              // Full "*" semantics (recursive...)
              for (var i = pathIndex; i < path.Length; i++) {
            // Stop at first path separator
            if (FileNameMatching.IsPathSeparator(path[i]))
              break;

            var result = Match(kind, comparer, operators, operatorIndex + 1, path, i);
            if (result == path.Length)
              return result;
              }

              return -1;
        }
Пример #22
0
        public bool MatchFileName(RelativePath relativePath, IPathComparer comparer)
        {
            if (relativePath.IsEmpty)
            {
                throw new ArgumentNullException("relativePath");
            }

            if (_fileExtensions.Contains(relativePath.Extension))
            {
                return(true);
            }

            // Note: Use "for" loop to avoid allocation if using "Any()"
            for (var index = 0; index < _pathMatchers.Length; index++)
            {
                if (_pathMatchers[index].MatchFileName(relativePath, comparer))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #23
0
        public bool MatchFileName(string path, IPathComparer comparer)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            if (_fileExtensions.Contains(Path.GetExtension(path)))
            {
                return(true);
            }

            // Note: Use "for" loop to avoid allocation if using "Any()"
            for (var index = 0; index < _pathMatchers.Length; index++)
            {
                if (_pathMatchers[index].MatchFileName(path, comparer))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #24
0
        public override int MatchWorker(MatchKind kind, IPathComparer comparer, IList <BaseOperator> operators, int operatorIndex, string path, int pathIndex)
        {
            // If we are the last operation, don't match
            if (operatorIndex == operators.Count - 1)
            {
                return(-1);
            }

            // If we reach the end of the "path", or we are not on a path separator, don't match
            if (pathIndex == path.Length || !FileNameMatching.IsPathSeparator(path[pathIndex]))
            {
                return(-1);
            }

            pathIndex++;

            while (pathIndex < path.Length)
            {
                var result = Match(kind, comparer, operators, operatorIndex + 1, path, pathIndex);
                if (result == path.Length)
                {
                    return(result);
                }

                // Look for next path separator in path
                var nextPathIndex = path.IndexOf(Path.DirectorySeparatorChar, pathIndex, path.Length - pathIndex);
                if (nextPathIndex < 0)
                {
                    break;
                }

                pathIndex = nextPathIndex + 1;
            }

            return(-1);
        }
Пример #25
0
 private bool MatchFileRelativePath(IPathMatcher matcher, FileName fileName, IPathComparer comparer)
 {
     return(matcher.MatchFileName(fileName.RelativePath, comparer));
 }
Пример #26
0
 public abstract int MatchWorker(MatchKind kind, IPathComparer comparer, IList <BaseOperator> operators, int operatorIndex, string path, int pathIndex);
Пример #27
0
 public bool PrePassWontMatch(MatchKind kind, string path, IPathComparer comparer) {
   return true;
 }
Пример #28
0
 public bool PrePassWontMatch(MatchKind kind, string path, IPathComparer comparer)
 {
     return(true);
 }
Пример #29
0
 public override int MatchWorker(MatchKind kind, IPathComparer comparer, IList <BaseOperator> operators, int operatorIndex, string path, int pathIndex)
 {
     return(-1);
 }
Пример #30
0
 public bool PrePassWontMatch(MatchKind kind, string path, IPathComparer comparer)
 {
     return path.IndexOf(_text, 0, path.Length, comparer.Comparison) < 0;
 }
Пример #31
0
 public abstract int MatchWorker(MatchKind kind, IPathComparer comparer, IList<BaseOperator> operators, int operatorIndex, string path, int pathIndex);
Пример #32
0
 public override int MatchWorker(MatchKind kind, IPathComparer comparer, IList<BaseOperator> operators, int operatorIndex, string path, int pathIndex) {
   return -1;
 }
Пример #33
0
 public bool PrePassWontMatch(MatchKind kind, string path, IPathComparer comparer) {
   return comparer.IndexOf(path, _text, 0, path.Length) < 0;
 }
Пример #34
0
 public static bool EndsWith(this IPathComparer comparer, string value, string searchText)
 {
     value      = (value ?? string.Empty);
     searchText = (searchText ?? string.Empty);
     return(comparer.IndexOf(value, searchText, 0, value.Length) == (value.Length - searchText.Length));
 }
Пример #35
0
 public bool PrePassWontMatch(MatchKind kind, string path, IPathComparer comparer)
 {
     return(path.IndexOf(_text, 0, path.Length, comparer.Comparison) < 0);
 }
Пример #36
0
 public bool MatchFileName(RelativePath path, IPathComparer comparer)
 {
     return(MatchRelativePath(path));
 }
Пример #37
0
 public bool MatchDirectoryName(RelativePath path, IPathComparer comparer)
 {
     return(MatchRelativePath(path));
 }
Пример #38
0
 public bool MatchFileName(RelativePath path, IPathComparer comparer)
 {
     return(false);
 }
Пример #39
0
 public bool MatchDirectoryName(RelativePath path, IPathComparer comparer)
 {
     return(false);
 }
Пример #40
0
        private bool MatchDirectoryRelativePath(IPathMatcher matcher, DirectoryName directoryName, IPathComparer comparer)
        {
            // "Chromium" root directories make it through here, skip them.
            if (directoryName.IsAbsoluteName)
            {
                return(false);
            }

            return(matcher.MatchDirectoryName(directoryName.RelativePathName.RelativeName, comparer));
        }
Пример #41
0
 public override int MatchWorker(MatchKind kind, IPathComparer comparer, IList<BaseOperator> operators, int operatorIndex, string path, int pathIndex) {
   if (pathIndex < path.Length && path[pathIndex] == Path.DirectorySeparatorChar)
     return Match(kind, comparer, operators, operatorIndex + 1, path, pathIndex + 1);
   return -1;
 }