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; }
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; }
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); }
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); }
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; }
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); }
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 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); }
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); }
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)); }
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); }
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)); }
/// <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); }
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; }
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; }
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; }
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; }
/// <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)); }
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); }
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; }
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); }
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); }
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); }
private bool MatchFileRelativePath(IPathMatcher matcher, FileName fileName, IPathComparer comparer) { return(matcher.MatchFileName(fileName.RelativePath, comparer)); }
public abstract int MatchWorker(MatchKind kind, IPathComparer comparer, IList <BaseOperator> operators, int operatorIndex, string path, int pathIndex);
public bool PrePassWontMatch(MatchKind kind, string path, IPathComparer comparer) { return true; }
public bool PrePassWontMatch(MatchKind kind, string path, IPathComparer comparer) { return(true); }
public override int MatchWorker(MatchKind kind, IPathComparer comparer, IList <BaseOperator> operators, int operatorIndex, string path, int pathIndex) { return(-1); }
public bool PrePassWontMatch(MatchKind kind, string path, IPathComparer comparer) { return path.IndexOf(_text, 0, path.Length, comparer.Comparison) < 0; }
public abstract int MatchWorker(MatchKind kind, IPathComparer comparer, IList<BaseOperator> operators, int operatorIndex, string path, int pathIndex);
public override int MatchWorker(MatchKind kind, IPathComparer comparer, IList<BaseOperator> operators, int operatorIndex, string path, int pathIndex) { return -1; }
public bool PrePassWontMatch(MatchKind kind, string path, IPathComparer comparer) { return comparer.IndexOf(path, _text, 0, path.Length) < 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)); }
public bool PrePassWontMatch(MatchKind kind, string path, IPathComparer comparer) { return(path.IndexOf(_text, 0, path.Length, comparer.Comparison) < 0); }
public bool MatchFileName(RelativePath path, IPathComparer comparer) { return(MatchRelativePath(path)); }
public bool MatchDirectoryName(RelativePath path, IPathComparer comparer) { return(MatchRelativePath(path)); }
public bool MatchFileName(RelativePath path, IPathComparer comparer) { return(false); }
public bool MatchDirectoryName(RelativePath path, IPathComparer comparer) { return(false); }
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)); }
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; }