-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuildHelper.cs
50 lines (47 loc) · 1.46 KB
/
BuildHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
using System.IO;
namespace AntTask
{
class BuildHelper
{
private static readonly char[] WHITESPACE_CHARS = new char[] { ' ', '\t', '\"' };
/// <summary>
/// Put a quote around the argument if it contains whitespace.
/// </summary>
/// <param name="argument">command line argument</param>
/// <returns>quoted argument only if necessary</returns>
public static string Quote(string argument)
{
if (argument == null)
{
return null;
}
if (argument.IndexOfAny(WHITESPACE_CHARS) >= 0)
{
// Check to see if argument already quoted.
if (argument.StartsWith("\"") && argument.EndsWith("\""))
{
return argument;
}
if (argument.StartsWith("\'") && argument.EndsWith("\'"))
{
return argument;
}
if (argument.IndexOf('"') >= 0)
{
// contains a ", wrap in '
return string.Format("'{0}'", argument);
}
else
{
// Just quote with "
return string.Format("\"{0}\"", argument);
}
}
return argument;
}
}
}