|
5 | 5 | using System.IO.Compression; |
6 | 6 | using System.Text.RegularExpressions; |
7 | 7 | using System.Threading.Tasks; |
8 | | -using Microsoft.International.Converters.PinYinConverter; |
| 8 | +using hyjiacan.py4n; |
9 | 9 | using K4os.Compression.LZ4.Streams; |
10 | 10 |
|
11 | 11 | namespace DwFramework.Core |
@@ -210,23 +210,28 @@ public static byte[] FromHex(this string hexString) |
210 | 210 | /// </summary> |
211 | 211 | /// <param name="char"></param> |
212 | 212 | /// <returns></returns> |
213 | | - public static bool IsChinese(this char @char) |
| 213 | + public static bool IsChinese(this char @char) => PinyinUtil.IsHanzi(@char); |
| 214 | + |
| 215 | + /// <summary> |
| 216 | + /// 获取中文字符的拼音首字母 |
| 217 | + /// </summary> |
| 218 | + /// <param name="@char"></param> |
| 219 | + /// <returns></returns> |
| 220 | + public static string GetFirstPinyin(this char @char) |
214 | 221 | { |
215 | | - var pattern = @"^[\u4e00-\u9fa5]$"; |
216 | | - if (Regex.IsMatch(@char.ToString(), pattern)) return true; |
217 | | - return false; |
| 222 | + if (!IsChinese(@char)) return null; |
| 223 | + return Pinyin4Net.GetFirstPinyin(@char, PinyinFormat.UPPERCASE); |
218 | 224 | } |
219 | 225 |
|
220 | 226 | /// <summary> |
221 | 227 | /// 获取中文字符的拼音 |
222 | 228 | /// </summary> |
223 | | - /// <param name="@char"></param> |
| 229 | + /// <param name="char"></param> |
224 | 230 | /// <returns></returns> |
225 | | - public static string[] GetPinYin(this char @char) |
| 231 | + public static string[] GetPinyin(this char @char) |
226 | 232 | { |
227 | 233 | if (!IsChinese(@char)) return null; |
228 | | - var decoder = new ChineseChar(@char); |
229 | | - return decoder.Pinyins; |
| 234 | + return Pinyin4Net.GetPinyin(@char, PinyinFormat.UPPERCASE); |
230 | 235 | } |
231 | 236 |
|
232 | 237 | /// <summary> |
|
0 commit comments