コード例 #1
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 = Path.GetDirectoryName(expression.AsSpan());

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

            switch (options.MatchType)
            {
            case MatchType.Win32:
                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.TranslateWin32Expression(expression);
                }
                break;

            case MatchType.Simple:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(options));
            }
        }
コード例 #2
0
 public void TranslateExpression(string expression, string expected)
 {
     Assert.Equal(expected, FileSystemName.TranslateWin32Expression(expression));
 }
コード例 #3
0
        public void TranslateVeryLongExpression()
        {
            string longString = new string('a', 10_000_000);

            Assert.Equal(longString, FileSystemName.TranslateWin32Expression(longString));
        }
コード例 #4
0
 /// <inheritdoc />
 public string TranslateWin32Expression(string expression)
 {
     return(FileSystemName.TranslateWin32Expression(expression));
 }