Skip to content
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