提交 fd307891 编写于 作者: C Charles Stoner

Address PR feedback

上级 cb6de686
......@@ -133,7 +133,7 @@ internal static string FormatLiteral(bool value)
return value ? "true" : "false";
}
private static void FormatChar(
private static void FormatStringChar(
ref PooledStringBuilder pooledBuilder,
string str,
int index,
......@@ -273,7 +273,7 @@ public static string FormatLiteral(string value, ObjectDisplayOptions options)
}
for (int i = 0; i < value.Length; i++)
{
FormatChar(ref pooledBuilder, value, i, value[i], quote, useLanguageSpecificEscapes: true, useUnicodeEscapes: true);
FormatStringChar(ref pooledBuilder, value, i, value[i], quote, useLanguageSpecificEscapes: true, useUnicodeEscapes: true);
}
if (quote != 0)
{
......@@ -295,7 +295,7 @@ internal static string FormatString(string str, bool useQuotes)
builder.Append(quote);
for (int i = 0; i < str.Length; i++)
{
FormatChar(ref pooledBuilder, str, i, str[i], quote, useLanguageSpecificEscapes: useQuotes, useUnicodeEscapes: false);
FormatStringChar(ref pooledBuilder, str, i, str[i], quote, useLanguageSpecificEscapes: useQuotes, useUnicodeEscapes: false);
}
builder.Append(quote);
return pooledBuilder.ToStringAndFree();
......@@ -320,13 +320,13 @@ internal static string FormatLiteral(char c, ObjectDisplayOptions options)
builder.Append(options.IncludesOption(ObjectDisplayOptions.UseHexadecimalNumbers) ? "0x" + ((int)c).ToString("x4") : ((int)c).ToString());
builder.Append(" ");
}
if (quote != 0)
if (useQuotes)
{
builder.Append(quote);
}
var escapeNonPrintable = !includeCodePoints;
FormatChar(ref pooledBuilder, null, 0, c, quote, useLanguageSpecificEscapes: useQuotes, useUnicodeEscapes: !includeCodePoints);
if (quote != 0)
FormatStringChar(ref pooledBuilder, null, 0, c, quote, useLanguageSpecificEscapes: useQuotes, useUnicodeEscapes: !includeCodePoints);
if (useQuotes)
{
builder.Append(quote);
}
......
......@@ -155,6 +155,7 @@ public void Strings()
}
var s = sb.ToString();
// Formatting with quotes should escape specific control characters.
var expected =
"\"\\0\u0001\u0002\u0003\u0004\u0005\u0006\\a\\b\\t\\n\\v\\f\\r\u000e\u000f\u0010" +
"\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d" +
......@@ -168,6 +169,7 @@ public void Strings()
expected,
ObjectDisplay.FormatString(s, useQuotes: true));
// Formatting without quotes should not escape any characters.
expected =
"\0\u0001\u0002\u0003\u0004\u0005\u0006\a\u0008\u0009\u000a\u000b\f\u000d\u000e\u000f\u0010" +
"\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d" +
......
......@@ -228,15 +228,16 @@ public void TestLiteralDefaultStringValues()
CheckLiteralToString("A", @"""A""");
CheckLiteralToString("\r", @"""\r""");
CheckLiteralToString("\u0007", @"""\a""");
CheckLiteralToString("\u000c", @"""\f""");
CheckLiteralToString("\u001f", @"""\u001f""");
// char
CheckLiteralToString('A', @"'A'");
CheckLiteralToString('\r', @"'\r'");
CheckLiteralToString('\u0007', @"'\a'");
CheckLiteralToString('\u000c', @"'\f'");
CheckLiteralToString('\u001f', @"'\u001f'");
// byte
CheckLiteralToString(byte.MinValue, @"0");
CheckLiteralToString(byte.MaxValue, @"255");
......
......@@ -107,9 +107,6 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="My Project\" />
</ItemGroup>
<Import Project="..\..\Source\ResultProvider\BasicResultProvider.projitems" Label="Shared" />
<ImportGroup Label="Targets">
<Import Project="..\..\..\..\Tools\Microsoft.CodeAnalysis.Toolset.Open\Targets\VSL.Imports.targets" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册