Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser for actual MSBuild Property option syntax #27086

Merged
Changes from 1 commit
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
24 changes: 12 additions & 12 deletions src/Cli/Microsoft.DotNet.Cli.Utils/MSBuildPropertyParser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
baronfel marked this conversation as resolved.
Show resolved Hide resolved
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;

#nullable enable

Expand All @@ -9,14 +10,14 @@ namespace Microsoft.DotNet.Cli.Utils;
public static class MSBuildPropertyParser {
public static IEnumerable<(string key, string value)> ParseProperties(string input) {
var currentPos = 0;
string? currentKey = null;
string? currentValue = null;
StringBuilder currentKey = new StringBuilder();
StringBuilder currentValue = new StringBuilder();

(string key, string value) EmitAndReset() {
var key = currentKey!;
var value= currentValue!;
currentKey = null;
currentValue = null;
var key = currentKey.ToString();
var value= currentValue.ToString();
currentKey = currentKey.Clear();
currentValue = currentValue.Clear();
baronfel marked this conversation as resolved.
Show resolved Hide resolved
return (key, value);
}

Expand All @@ -35,32 +36,31 @@ bool TryConsume(out char? consumed) {

void ParseKey() {
while (TryConsume(out var c) && c != '=') {
currentKey += c;
currentKey.Append(c);
}
}

void ParseQuotedValue() {
TryConsume(out var leadingQuote); // consume the leading quote, which we know is there
currentValue += leadingQuote;
currentValue.Append(leadingQuote);
while(TryConsume(out char? c)) {
currentValue.Append(c);
if (c == '"') {
currentValue += c;
// we're done
return;
}
currentValue += c;
if (c == '\\' && Peek() == '"')
{
// consume the escaped quote
TryConsume(out var c2);
currentValue += c2;
currentValue.Append(c2);
}
}
}

void ParseUnquotedValue() {
while(TryConsume(out char? c) && c != ';') {
currentValue += c;
currentValue.Append(c);
}
}

Expand Down