mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 11:16:51 +02:00
Use Unidecoder instead of ChineseToPinYin
// Please do not use the binary version on NuGet since there are some issues with the data table
This commit is contained in:
37
Wox.Infrastructure/Unidecoder.cs
Normal file
37
Wox.Infrastructure/Unidecoder.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Wox.Infrastructure
|
||||
{
|
||||
public static partial class Unidecoder
|
||||
{
|
||||
public static string Unidecode(this string self)
|
||||
{
|
||||
if (string.IsNullOrEmpty(self))
|
||||
return "";
|
||||
|
||||
if (self.All(x => x < 128))
|
||||
return self;
|
||||
|
||||
return String.Join("", self.Select(c => c.Unidecode()).ToArray());
|
||||
}
|
||||
|
||||
public static string Unidecode(this char c)
|
||||
{
|
||||
string result;
|
||||
if (c < 128)
|
||||
return char.ToString(c);
|
||||
|
||||
int high = c >> 8;
|
||||
int low = c & 0xff;
|
||||
string[] t;
|
||||
|
||||
if (characters.TryGetValue(high, out t))
|
||||
return t[low];
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user