Exemple #1
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);
        }
Exemple #2
0
        private static bool IsMatch(string path, int result)
        {
            if (result < -1 || result > path.Length)
            {
                throw new InvalidOperationException("Invalid result! (Bug)");
            }

            if (result == -1)
            {
                return(false);
            }

            if (result == path.Length)
            {
                return(true);
            }

            if (FileNameMatching.IsPathSeparator(path[result]))
            {
                return(true);
            }

            return(false);
        }
        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);
        }