Skip to content

Commit b10a6e1

Browse files
Capitalize first letter
1 parent f673000 commit b10a6e1

File tree

1 file changed

+41
-43
lines changed

1 file changed

+41
-43
lines changed

Flow.Launcher.Infrastructure/PinyinAlphabet.cs

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -46,71 +46,69 @@ public bool ShouldTranslate(string stringToTranslate)
4646

4747
private (string translation, TranslationMapping map) BuildCacheFromContent(string content)
4848
{
49-
if (WordsHelper.HasChinese(content))
49+
if (!WordsHelper.HasChinese(content))
5050
{
51-
var resultList = WordsHelper.GetPinyinList(content);
51+
return (content, null);
52+
}
5253

53-
StringBuilder resultBuilder = new StringBuilder();
54-
TranslationMapping map = new TranslationMapping();
54+
var resultList = WordsHelper.GetPinyinList(content);
5555

56-
bool pre = false;
56+
StringBuilder resultBuilder = new StringBuilder();
57+
TranslationMapping map = new TranslationMapping();
5758

58-
for (int i = 0; i < resultList.Length; i++)
59+
bool pre = false;
60+
61+
for (int i = 0; i < resultList.Length; i++)
62+
{
63+
if (content[i] >= 0x3400 && content[i] <= 0x9FD5)
5964
{
60-
if (content[i] >= 0x3400 && content[i] <= 0x9FD5)
65+
string dp = _settings.UseDoublePinyin ? ToDoublePin(resultList[i]) : resultList[i];
66+
map.AddNewIndex(i, resultBuilder.Length, dp.Length + 1);
67+
resultBuilder.Append(' ');
68+
resultBuilder.Append(dp);
69+
pre = true;
70+
}
71+
else
72+
{
73+
if (pre)
6174
{
62-
string dp = _settings.UseDoublePinyin ? ToDoublePin(resultList[i].ToLower()) : resultList[i];
63-
map.AddNewIndex(i, resultBuilder.Length, dp.Length + 1);
75+
pre = false;
6476
resultBuilder.Append(' ');
65-
resultBuilder.Append(dp);
66-
pre = true;
6777
}
68-
else
69-
{
70-
if (pre)
71-
{
72-
pre = false;
73-
resultBuilder.Append(' ');
74-
}
7578

76-
resultBuilder.Append(resultList[i]);
77-
}
79+
resultBuilder.Append(resultList[i]);
7880
}
81+
}
7982

80-
map.endConstruct();
83+
map.endConstruct();
8184

82-
var key = resultBuilder.ToString();
83-
map.setKey(key);
85+
var key = resultBuilder.ToString();
86+
map.setKey(key);
8487

85-
return _pinyinCache[content] = (key, map);
86-
}
87-
else
88-
{
89-
return (content, null);
90-
}
88+
return _pinyinCache[content] = (key, map);
9189
}
9290

9391
#region Double Pinyin
9492

9593
private static readonly ReadOnlyDictionary<string, string> special = new(new Dictionary<string, string>(){
96-
{"a", "aa"},
97-
{"ai", "ai"},
98-
{"an", "an"},
99-
{"ang", "ah"},
100-
{"ao", "ao"},
101-
{"e", "ee"},
102-
{"ei", "ei"},
103-
{"en", "en"},
104-
{"er", "er"},
105-
{"o", "oo"},
106-
{"ou", "ou"}
94+
{"A", "aa"},
95+
{"Ai", "ai"},
96+
{"An", "an"},
97+
{"Ang", "ah"},
98+
{"Ao", "ao"},
99+
{"E", "ee"},
100+
{"Ei", "ei"},
101+
{"En", "en"},
102+
{"Er", "er"},
103+
{"O", "oo"},
104+
{"Ou", "ou"}
107105
});
108106

109107

110108
private static readonly ReadOnlyDictionary<string, string> first = new(new Dictionary<string, string>(){
111-
{"ch", "i"},
112-
{"sh", "u"},
113-
{"zh", "v"}
109+
{"Ch", "i"},
110+
{"Sh", "u"},
111+
{"Zh", "v"}
114112
});
115113

116114

0 commit comments

Comments
 (0)