Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 30 additions & 21 deletions src/Compilers/Core/Portable/CommandLine/CommandLineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,32 +98,39 @@ internal static bool IsOptionName(string shortOptionName, string longOptionName,
/// </remarks>
internal static bool IsOptionName(string optionName, ReadOnlySpan<char> value)
{
Debug.Assert(isAllAscii(optionName.AsSpan()));
if (isAllAscii(value))
assertAllAscii(optionName.AsSpan());

if (optionName.Length != value.Length)
return false;

for (int i = 0; i < optionName.Length; i++)
{
if (optionName.Length != value.Length)
return false;
char ch = value[i];
if (ch > 127)
{
// If a non-ascii character is encountered, do an InvariantCultureIgnoreCase comparison
return optionName.AsSpan().Equals(value, StringComparison.InvariantCultureIgnoreCase);
}

for (int i = 0; i < optionName.Length; i++)
if (optionName[i] != char.ToLowerInvariant(ch))
{
if (optionName[i] != char.ToLowerInvariant(value[i]))
{
return false;
}
return false;
}
return true;
}

return optionName.AsSpan().Equals(value, StringComparison.InvariantCultureIgnoreCase);
return true;

static bool isAllAscii(ReadOnlySpan<char> span)
[Conditional("DEBUG")]
static void assertAllAscii(ReadOnlySpan<char> span)
{
foreach (char ch in span)
{
if (ch > 127)
return false;
{
Debug.Assert(false);
break;
}
}
return true;
}
}

Expand Down Expand Up @@ -167,16 +174,19 @@ internal static bool TryParseOption(string arg, out ReadOnlyMemory<char> name, o
return true;
}

int colon = arg.IndexOf(':');
int colon = arg.IndexOf(':', 1);

// temporary heuristic to detect Unix-style rooted paths
// pattern /goo/* or //* will not be treated as a compiler option
//
// TODO: consider introducing "/s:path" to disambiguate paths starting with /
if (arg.Length > 1 && arg[0] != '-')
{
int separator = arg.IndexOf('/', 1);
if (separator > 0 && (colon < 0 || separator < colon))
int separator = colon < 0
? arg.IndexOf('/', 1)
: arg.IndexOf('/', 1, colon - 1);

if (separator > 0)
{
// "/goo/
// "//
Expand Down Expand Up @@ -1064,11 +1074,10 @@ internal static void ParseSeparatedStrings(ReadOnlyMemory<char>? strMemory, char
{
inQuotes = !inQuotes;
}

if (!inQuotes && separators.IndexOf(c) >= 0)
else if (!inQuotes && separators.Contains(c))
{
var current = memory.Slice(nextPiece, i - nextPiece);
if (!removeEmptyEntries || current.Length > 0)
if (current.Length > 0 || !removeEmptyEntries)
{
builder.Add(current);
}
Expand All @@ -1078,7 +1087,7 @@ internal static void ParseSeparatedStrings(ReadOnlyMemory<char>? strMemory, char
}

var last = memory.Slice(nextPiece);
if (!removeEmptyEntries || last.Length > 0)
if (last.Length > 0 || !removeEmptyEntries)
{
builder.Add(last);
}
Expand Down