Move portable thread pool to shared partition (dotnet/corert#7828)
[mono-project.git] / netcore / System.Private.CoreLib / shared / System / PasteArguments.Windows.cs
blobe760a401658ed981d83f3da0c920159760a4b646
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 using System.Collections.Generic;
6 using System.Text;
8 namespace System
10 internal static partial class PasteArguments
12 /// <summary>
13 /// Repastes a set of arguments into a linear string that parses back into the originals under pre- or post-2008 VC parsing rules.
14 /// The rules for parsing the executable name (argv[0]) are special, so you must indicate whether the first argument actually is argv[0].
15 /// </summary>
16 internal static string Paste(IEnumerable<string> arguments, bool pasteFirstArgumentUsingArgV0Rules)
18 var stringBuilder = new StringBuilder();
20 foreach (string argument in arguments)
22 if (pasteFirstArgumentUsingArgV0Rules)
24 pasteFirstArgumentUsingArgV0Rules = false;
26 // Special rules for argv[0]
27 // - Backslash is a normal character.
28 // - Quotes used to include whitespace characters.
29 // - Parsing ends at first whitespace outside quoted region.
30 // - No way to get a literal quote past the parser.
32 bool hasWhitespace = false;
33 foreach (char c in argument)
35 if (c == Quote)
37 throw new ApplicationException("The argv[0] argument cannot include a double quote.");
39 if (char.IsWhiteSpace(c))
41 hasWhitespace = true;
44 if (argument.Length == 0 || hasWhitespace)
46 stringBuilder.Append(Quote);
47 stringBuilder.Append(argument);
48 stringBuilder.Append(Quote);
50 else
52 stringBuilder.Append(argument);
55 else
57 AppendArgument(stringBuilder, argument);
61 return stringBuilder.ToString();