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

remove quotes around printed enums #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 10 additions & 5 deletions src/protobuf.Text/TextFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public void WriteValue(TextWriter writer, object value)
string name = OriginalEnumValueHelper.GetOriginalName(value);
if (name != null)
{
WriteString(writer, name);
WriteString(writer, name, false);
}
else
{
Expand Down Expand Up @@ -753,14 +753,17 @@ internal void WriteDictionary(TextWriter writer, IDictionary dictionary)
}

/// <summary>
/// Writes a string (including leading and trailing double quotes) to a builder, escaping as required.
/// Writes a string (including leading and trailing double quotes if addQuotesAroundString is true) to a builder, escaping as required.
/// </summary>
/// <remarks>
/// Other than surrogate pair handling, this code is mostly taken from src/google/protobuf/util/internal/json_escaping.cc.
/// </remarks>
internal static void WriteString(TextWriter writer, string text)
internal static void WriteString(TextWriter writer, string text, bool addQuotesAroundString = true)
{
writer.Write('"');
if(addQuotesAroundString) {
writer.Write('"');
}

for (int i = 0; i < text.Length; i++)
{
char c = text[i];
Expand Down Expand Up @@ -820,7 +823,9 @@ internal static void WriteString(TextWriter writer, string text)
break;
}
}
writer.Write('"');
if(addQuotesAroundString) {
writer.Write('"');
}
}

private const string Hex = "0123456789abcdef";
Expand Down