mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Update PinyinAlphabet.cs
optimize Chinese character check logic Co-Authored-By: ToolGood <toolgood@qq.com>
This commit is contained in:
parent
d64b4b5b0c
commit
64d67c1aa5
1 changed files with 15 additions and 20 deletions
|
|
@ -39,37 +39,32 @@ namespace Flow.Launcher.Infrastructure
|
|||
{
|
||||
var resultList = WordsHelper.GetPinyinList(content);
|
||||
|
||||
List<int> chineseIndexs = new List<int>();
|
||||
|
||||
for (int i = 0; i < content.Length; i++)
|
||||
{
|
||||
if (resultList[i].Length != 1 || !(resultList[i][0] == content[i]))
|
||||
chineseIndexs.Add(i);
|
||||
}
|
||||
StringBuilder resultBuilder = new StringBuilder();
|
||||
|
||||
|
||||
foreach (var chineseIndex in chineseIndexs)
|
||||
{
|
||||
resultBuilder.Append(resultList[chineseIndex].First());
|
||||
}
|
||||
resultBuilder.Append(' ');
|
||||
|
||||
int currentChineseIndex = 0;
|
||||
int lastChineseIndex = -1;
|
||||
for (int i = 0; i < resultList.Length; i++)
|
||||
{
|
||||
if (currentChineseIndex < chineseIndexs.Count && chineseIndexs[currentChineseIndex] == i)
|
||||
if (content[i] >= 0x3400 && content[i] <= 0x9FD5)
|
||||
resultBuilder.Append(resultList[i].First());
|
||||
}
|
||||
|
||||
resultBuilder.Append(' ');
|
||||
|
||||
bool pre = false;
|
||||
|
||||
for (int i = 0; i < resultList.Length; i++)
|
||||
{
|
||||
if (content[i] >= 0x3400 && content[i] <= 0x9FD5)
|
||||
{
|
||||
resultBuilder.Append(' ');
|
||||
|
||||
resultBuilder.Append(resultList[i]);
|
||||
currentChineseIndex++;
|
||||
lastChineseIndex = i;
|
||||
pre = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i == lastChineseIndex + 1)
|
||||
if (pre)
|
||||
{
|
||||
pre = false;
|
||||
resultBuilder.Append(' ');
|
||||
}
|
||||
resultBuilder.Append(resultList[i]);
|
||||
|
|
|
|||
Loading…
Reference in a new issue