From c9c3e0b9be86d59e2bf93fd2c57f4c8cf10b6fc0 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 19 Jul 2016 12:27:09 -0700 Subject: [PATCH] Remove managed CommandLineToArgv It is entirely unused. --- .../CoreCLR/CorePsPlatform.cs | 59 ---------- test/csharp/test_CorePsPlatform.cs | 107 ------------------ 2 files changed, 166 deletions(-) diff --git a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs index 7ce0a44196..9171933bb5 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs @@ -367,65 +367,6 @@ namespace System.Management.Automation // TODO:PSL clean this up return 0; } - - /// - /// This models the native call CommandLineToArgvW in managed code. - /// - internal static string[] CommandLineToArgv(string command) - { - StringBuilder arguments = new StringBuilder(); - int len = command.Length; - IList returnList = new List(); - bool inquote = false; - char current = '\0'; - - for (int argIndex = 0; argIndex < len; argIndex++) - { - current = command[argIndex]; - - if (current.Equals('"')) - { - // Treat anything in quotes as a single argument - // Because C# treats quotes differently than C++, instead of counting the slashes - // it makes more sense to count the quotes. - inquote = !inquote; - arguments.Append('"'); - continue; - } - - // If we're inside a quote, add the current character and cycle through - if (inquote && !current.Equals('"')) - { - arguments.Append(current.ToString()); - continue; - } - - if (current.Equals("\\")) - { - arguments.Append("\\"); - continue; - } - - if (string.IsNullOrWhiteSpace(current.ToString())) - { - if (arguments.Length > 0) - { - returnList.Add(arguments.ToString()); - arguments.Clear(); - } - continue; - } - - // All other exclusion scenarios being exhausted, append the current character. - arguments.Append(current.ToString()); - } - - // add the final object to the arguments list - returnList.Add(arguments.ToString()); - arguments.Clear(); - - return returnList.ToArray(); - } } internal static class Unix diff --git a/test/csharp/test_CorePsPlatform.cs b/test/csharp/test_CorePsPlatform.cs index 80d3878918..2a6fa2d94a 100644 --- a/test/csharp/test_CorePsPlatform.cs +++ b/test/csharp/test_CorePsPlatform.cs @@ -255,112 +255,5 @@ namespace PSTests File.Delete(path); File.Delete(link); } - - [Fact] - public static void TestCommandLineArgvReturnsAnElement() - { - string testCommand= "Today"; - - string[] retval = Platform.CommandLineToArgv(testCommand); - - Assert.Equal(1, retval.Length); - } - - [Fact] - public static void TestCommandLineArgvWWithSpaces() - { - string testCommand= "Today is a good day or is it"; - - string[] retval = Platform.CommandLineToArgv(testCommand); - - Assert.Equal("Today", retval[0]); - Assert.Equal("is", retval[1]); - Assert.Equal("a", retval[2]); - Assert.Equal("good", retval[3]); - Assert.Equal("day", retval[4]); - Assert.Equal("or", retval[5]); - Assert.Equal("is", retval[6]); - Assert.Equal("it", retval[7]); - } - - [Fact] - public static void TestCommandLineToArgvWTabsAreTreatedAsSpaces() - { - string testCommand = "Today \t is a good day"; - - string[] retval = Platform.CommandLineToArgv(testCommand); - - Assert.Equal("Today", retval[0]); - Assert.Equal("is", retval[1]); - Assert.Equal("a", retval[2]); - Assert.Equal("good", retval[3]); - Assert.Equal("day", retval[4]); - } - - [Fact] - public static void TestCommandLineToArgvWQuotesAreArgs() - { - string testCommand = "Today is \"a good\" day"; - - string[] retval = Platform.CommandLineToArgv(testCommand); - - Assert.Equal(4, retval.Length); - Assert.Equal("Today", retval[0]); - Assert.Equal("is", retval[1]); - Assert.Equal("\"a good\"", retval[2]); - Assert.Equal("day", retval[3]); - } - - [Fact] - public static void TestCommandLineToArgvWEvenNumberBackSlashes() - { - string test1 = "a\\b c d"; - string test2 = "a\\b\\c d"; - string test3 = "a \\b\\c\\d"; - string test4 = "a\\\\\\b"; - string[] retval; - - retval = Platform.CommandLineToArgv(test1); - - Assert.Equal(3, retval.Length); - Assert.Equal("a\\b", retval[0]); - Assert.Equal("c", retval[1]); - Assert.Equal("d", retval[2]); - - retval = Platform.CommandLineToArgv(test2); - - Assert.Equal(2, retval.Length); - Assert.Equal("a\\b\\c", retval[0]); - Assert.Equal("d", retval[1]); - - retval = Platform.CommandLineToArgv(test3); - - Assert.Equal(2, retval.Length); - Assert.Equal("a", retval[0]); - Assert.Equal("\\b\\c\\d", retval[1]); - - retval = Platform.CommandLineToArgv(test4); - - Assert.Equal(1, retval.Length); - Assert.Equal("a\\\\\\b", retval[0]); - } - - [Fact] - public static void TestCommandLineToArgvwOddNumberWithBackSlashes() - { - string test1 = "a\\\"b"; - string test2 = "a\\\\\\\"b"; - string[] retval; - - retval = Platform.CommandLineToArgv(test1); - - Assert.Equal(1, retval.Length); - Assert.Equal("a\\\"b", retval[0]); - - retval = Platform.CommandLineToArgv(test2); - - Assert.Equal(1, retval.Length); - Assert.Equal("a\\\\\\\"b", retval[0]); - } } }