Skip to content

Commit

Permalink
Fix display of special characters in the debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Feb 21, 2015
1 parent 9ecc977 commit 7f96a55
Showing 1 changed file with 59 additions and 7 deletions.
66 changes: 59 additions & 7 deletions Tvl.VisualStudio.Language.Java/Debugger/JavaDebugProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Diagnostics.Contracts;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Debugger.Interop;
using Tvl.Java.DebugInterface;
Expand Down Expand Up @@ -811,14 +812,65 @@ private static string EscapeSpecialCharacters(string value, int maxLength, char
if (cropped)
value = value.Substring(0, maxLength) + "...";

// TODO: handle all escape characters
value = value.Replace("\\", "\\\\").Replace("\r", "\\r").Replace("\t", "\\t").Replace("\n", "\\n").Replace(quoteCharacter.ToString(), "\\" + quoteCharacter);
if (cropped)
value = quoteCharacter + value;
else
value = quoteCharacter + value + quoteCharacter;
StringBuilder result = new StringBuilder(value.Length + 2);
result.Append(quoteCharacter);

foreach (char ch in value)
{
switch (ch)
{
case '\\':
result.Append("\\\\");
continue;

case '\r':
result.Append("\\r");
continue;

case '\n':
result.Append("\\n");
continue;

case '\t':
result.Append("\\t");
continue;

case '\f':
result.Append("\\f");
continue;

case '\'':
if (quoteCharacter != '\'')
goto default;

result.Append("\\'");
continue;

case '"':
if (quoteCharacter != '"')
goto default;

result.Append("\\\"");
continue;

case '\b':
result.Append("\\b");
continue;

default:
// TODO: reduce these to octal escapes where possible
if (char.IsControl(ch))
result.Append("\\u").Append(((int)ch).ToString("X4"));
else
result.Append(ch);
continue;
}
}

if (!cropped)
result.Append(quoteCharacter);

return value;
return result.ToString();
}

/// <summary>
Expand Down

0 comments on commit 7f96a55

Please sign in to comment.