private static bool MatchesPattern(string expression, ReadOnlySpan <char> name, EnumerationOptions options)
        {
            bool ignoreCase = (options.MatchCasing == MatchCasing.PlatformDefault && !PathInternal.IsCaseSensitive) ||
                              options.MatchCasing == MatchCasing.CaseInsensitive;

            return(options.MatchType switch
            {
                MatchType.Simple => FileSystemName.MatchesSimpleExpression(expression.AsSpan(), name, ignoreCase),
                MatchType.Win32 => FileSystemName.MatchesWin32Expression(expression.AsSpan(), name, ignoreCase),
                _ => throw new ArgumentOutOfRangeException(nameof(options)),
            });
Example #2
0
        private static bool MatchesPattern(string expression, ReadOnlySpan <char> name, EnumerationOptions options)
        {
            bool ignoreCase = (options.MatchCasing == MatchCasing.PlatformDefault && !PathInternal.IsCaseSensitive) ||
                              options.MatchCasing == MatchCasing.CaseInsensitive;

            switch (options.MatchType)
            {
            case MatchType.Simple:
                return(FileSystemName.MatchesSimpleExpression(expression, name, ignoreCase));

            case MatchType.Dos:
                return(FileSystemName.MatchesDosExpression(expression, name, ignoreCase));

            default:
                throw new ArgumentOutOfRangeException(nameof(options));
            }
        }
 public FileSystemEnumerator(string directory, EnumerationOptions options = null)
 {
 }
Example #4
0
        internal static void NormalizeInputs(ref string directory, ref string expression, EnumerationOptions options)
        {
            if (Path.IsPathRooted(expression))
            {
                throw new ArgumentException(SR.Arg_Path2IsRooted, nameof(expression));
            }

            // We always allowed breaking the passed ref directory and filter to be separated
            // any way the user wanted. Looking for "C:\foo\*.cs" could be passed as "C:\" and
            // "foo\*.cs" or "C:\foo" and "*.cs", for example. As such we need to combine and
            // split the inputs if the expression contains a directory separator.
            //
            // We also allowed for expression to be "foo\" which would translate to "foo\*".

            ReadOnlySpan <char> directoryName = PathHelpers.GetDirectoryNameNoChecks(expression.AsReadOnlySpan());

            if (directoryName.Length != 0)
            {
                // Need to fix up the input paths
                directory  = PathHelpers.CombineNoChecks(directory, directoryName);
                expression = expression.Substring(directoryName.Length + 1);
            }

            switch (options.MatchType)
            {
            case MatchType.Dos:
                if (string.IsNullOrEmpty(expression) || expression == "." || expression == "*.*")
                {
                    // Historically we always treated "." as "*"
                    expression = "*";
                }
                else
                {
                    if (Path.DirectorySeparatorChar != '\\' && expression.IndexOfAny(s_unixEscapeChars) != -1)
                    {
                        // Backslash isn't the default separator, need to escape (e.g. Unix)
                        expression = expression.Replace("\\", "\\\\");

                        // Also need to escape the other special wild characters ('"', '<', and '>')
                        expression = expression.Replace("\"", "\\\"");
                        expression = expression.Replace(">", "\\>");
                        expression = expression.Replace("<", "\\<");
                    }

                    // Need to convert the expression to match Win32 behavior
                    expression = FileSystemName.TranslateDosExpression(expression);
                }
                break;

            case MatchType.Simple:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(options));
            }
        }