forked from NESStudio/APTXCODE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CHConvert.cs
40 lines (34 loc) · 1.18 KB
/
CHConvert.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
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Globalization;
namespace Aptxcode
{
sealed class CHConvert
{
private CHConvert()
{ }
public static string MapString(CultureInfo ci, uint mapFlags, string srcStr)
{
StringBuilder lpDestStr = new StringBuilder(srcStr.Length);
if (NativeMethods.LCMapString((uint)ci.LCID, mapFlags, srcStr, srcStr.Length, lpDestStr, srcStr.Length) == 0)
throw new Win32Exception(Marshal.GetLastWin32Error());
else
return lpDestStr.ToString();
}
public static string MapString(uint mapFlags, string source)
{
return MapString(CurrentThreadCultureInfo(), mapFlags, source);
}
private static CultureInfo CurrentThreadCultureInfo()
{
return System.Threading.Thread.CurrentThread.CurrentCulture;
}
public static string ConvChsToCht(string srcStr)
{
return MapString(new CultureInfo("zh-CN", false), NativeMethods.LCMAP_TRADITIONAL_CHINESE, srcStr);
}
}
}