Skip to content

Commit 16b9149

Browse files
committed
fix output string
1 parent 8965f36 commit 16b9149

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

PythonConsoleControl/PythonOutputStream.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright (c) 2010 Joe Moorhouse
22

3+
using System;
34
using System.IO;
45
using System.Text;
6+
using System.Text.RegularExpressions;
57

68
namespace PythonConsoleControl
79
{
@@ -63,8 +65,18 @@ public override int Read(byte[] buffer, int offset, int count)
6365
/// </summary>
6466
public override void Write(byte[] buffer, int offset, int count)
6567
{
66-
string text = UTF8Encoding.UTF8.GetString(buffer, offset, count);
68+
string text = Encoding.UTF8.GetString(buffer, offset, count);
69+
text = DecodeUnicodeEscapes(text);
6770
textEditor.Write(text);
6871
}
72+
private string DecodeUnicodeEscapes(string input)
73+
{
74+
return Regex.Replace(input, @"\\u[0-9a-fA-F]{4}", match =>
75+
{
76+
var hex = match.Value.Substring(2);
77+
int charValue = Convert.ToInt32(hex, 16);
78+
return char.ConvertFromUtf32(charValue);
79+
});
80+
}
6981
}
7082
}

0 commit comments

Comments
 (0)