-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonHelpers.cs
More file actions
36 lines (34 loc) · 1005 Bytes
/
PythonHelpers.cs
File metadata and controls
36 lines (34 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
namespace ReplaysOfTheVoid
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class PythonHelpers
{
public static string Conv2String(dynamic value)
{
if (value is IronPython.Runtime.Bytes)
{
IronPython.Runtime.Bytes v = value;
return Encoding.UTF8.GetString(v.ToByteArray());
}
else if (value is string)
{
// redo encoding to unicode, was assumed to be ANSI while string was UTF8
string v = value;
byte[] arr = new byte[v.Length];
for (var i = 0; i < v.Length; i++)
{
arr[i] = (byte)v[i];
}
return Encoding.UTF8.GetString(arr);
}
else
{
throw new Exception("unknown type");
}
}
}
}