-
Notifications
You must be signed in to change notification settings - Fork 0
/
Encoding.cs
66 lines (50 loc) · 2.13 KB
/
Encoding.cs
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System.Text;
using Microsoft.PowerShell.Commands;
namespace PsUtils {
public class CmdletEncoding {
// From https://github.com/PowerShell/PowerShell/blob/5cbf1b43de52fe9025bf756990b1cc6eb4e694e9/src/System.Management.Automation/engine/Utils.cs
public static Encoding Convert(FileSystemCmdletProviderEncoding encoding) {
Encoding result = Encoding.Unicode;
switch (encoding) {
case FileSystemCmdletProviderEncoding.String:
result = new UnicodeEncoding();
break;
case FileSystemCmdletProviderEncoding.Unicode:
result = new UnicodeEncoding();
break;
case FileSystemCmdletProviderEncoding.BigEndianUnicode:
result = new UnicodeEncoding(true, false);
break;
case FileSystemCmdletProviderEncoding.UTF8:
result = new UTF8Encoding();
break;
case FileSystemCmdletProviderEncoding.UTF7:
result = new UTF7Encoding();
break;
case FileSystemCmdletProviderEncoding.UTF32:
result = new UTF32Encoding();
break;
/*
case FileSystemCmdletProviderEncoding.BigEndianUTF32:
result = new UTF32Encoding(true, false);
break;
*/
case FileSystemCmdletProviderEncoding.Ascii:
result = new ASCIIEncoding();
break;
case FileSystemCmdletProviderEncoding.Default:
result = Encoding.Default;
break;
case FileSystemCmdletProviderEncoding.Oem:
// Proper implementation done via PInvoke
result = Encoding.Default;
break;
default:
// Default to unicode encoding
result = new UnicodeEncoding();
break;
}
return result;
}
}
}