Skip to content

Commit f959a3d

Browse files
committed
convert non-printable char to unicode point
1 parent 8b35e0b commit f959a3d

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

Cs2Mermaid.Lib/ConvertCsToMermaid.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,19 @@ static void ConvertInternal(TextWriter tw, string currentNodeName, SyntaxNode no
128128
}
129129
else
130130
{
131-
tw.WriteLine($"{indent}{currentNodeName} --> {childNodeName}[\"{child.Kind()} {child.ToString()}\"]");
131+
var tokenString = child.ToString().Aggregate(new StringBuilder(), (sb, c) =>
132+
{
133+
if(char.IsWhiteSpace(c) || c == '"' || char.IsControl(c))
134+
{
135+
sb.Append("\\u" + ((int)c).ToString("x04"));
136+
}
137+
else
138+
{
139+
sb.Append(c);
140+
}
141+
return sb;
142+
}).ToString();
143+
tw.WriteLine($"{indent}{currentNodeName} --> {childNodeName}[\"{child.Kind()} {tokenString}\"]");
132144
}
133145
}
134146
if (!hasChild)

Cs2Mermaid.Test/ConvertTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,6 @@ public void LangVersionTest()
9999
options.LangVersion = "CSharp10";
100100
var cs10_0 = ConvertCsToMermaid.Convert(code, options);
101101
_OutputHelper.WriteLine("cs10 = " + cs10_0);
102+
Assert.NotEqual(cs10_0, cs7_3);
102103
}
103104
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class CDoubleQuote
2+
{
3+
string x = "yyyyy";
4+
string y = @"
5+
abcde
6+
";
7+
}

0 commit comments

Comments
 (0)