Files
UnrealEngineUWP/Engine/Source/Programs/Shared/EpicGames.Build/Automation/FormatCommandLine.cs
jonathan adamczewski db8046e278 Move DotNETCommon/BuildUtilities to Shared/EpicGames.Build
Also moves DotNETCommon/Metadata.cs to Shared/Metadata.cs

#jira none
#rb tim.smith

[CL 17116964 by jonathan adamczewski in ue5-main branch]
2021-08-10 11:08:41 -04:00

57 lines
1.7 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Text;
namespace UnrealBuildBase
{
public partial class CommandLine
{
/// <summary>
/// Converts a list of arguments to a string where each argument is separated with a space character.
/// </summary>
/// <param name="Args">Arguments</param>
/// <returns>Single string containing all arguments separated with a space.</returns>
public static string FormatCommandLine(IEnumerable<string> Arguments)
{
StringBuilder Result = new StringBuilder();
foreach(string Argument in Arguments)
{
if(Result.Length > 0)
{
Result.Append(" ");
}
Result.Append(FormatArgumentForCommandLine(Argument));
}
return Result.ToString();
}
/// <summary>
/// Format a single argument for passing on the command line, inserting quotes as necessary.
/// </summary>
/// <param name="Argument">The argument to quote</param>
/// <returns>The argument, with quotes if necessary</returns>
public static string FormatArgumentForCommandLine(string Argument)
{
// Check if the argument contains a space. If not, we can just pass it directly.
int SpaceIdx = Argument.IndexOf(' ');
if(SpaceIdx == -1)
{
return Argument;
}
// If it does have a space, and it's formatted as an option (ie. -Something=), try to insert quotes after the equals character
int EqualsIdx = Argument.IndexOf('=');
if(Argument.StartsWith("-") && EqualsIdx != -1 && EqualsIdx < SpaceIdx)
{
return String.Format("{0}=\"{1}\"", Argument.Substring(0, EqualsIdx), Argument.Substring(EqualsIdx + 1));
}
else
{
return String.Format("\"{0}\"", Argument);
}
}
}
}