Ejemplo n.º 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)
            {
                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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }