private static ChineseCharUnit[] GetChineseCharUnits() { List <ChineseCharUnit> list = new List <ChineseCharUnit>(); using (MemoryStream stream = new MemoryStream(Resources.ChineseCharUnits)) { using (BinaryReader reader = new BinaryReader(stream)) { int length = reader.ReadInt32(); for (int i = 0; i < length; i++) { int pinyinsCount = reader.ReadByte(); ushort[] pinyins = new ushort[pinyinsCount]; for (int j = 0; j < pinyinsCount; j++) { pinyins[j] = reader.ReadUInt16(); } byte strokeNumber = reader.ReadByte(); char simplified = reader.ReadChar(); char traditional = reader.ReadChar(); ChineseCharUnit ch = new ChineseCharUnit(pinyins, strokeNumber, simplified, traditional); list.Add(ch); } reader.Close(); } } return(list.ToArray()); }
/// <summary> /// 尝试获取表示中文汉字信息的 <see cref="ChineseCharUnit"/> 结构对象。如果传入的字符不是一个中文字符,则会获取失败。 /// 如果获取失败,则输出参数 <paramref name="result"/> 将会被设置为 <see cref="ChineseCharUnit.Empty"/>。 /// </summary> /// <param name="c"></param> /// <param name="result"></param> /// <returns></returns> public static bool TryGetCharUnit(char c, out ChineseCharUnit result) { int i = Array.BinarySearch(ChineseChars, c); if (i >= 0) { result = ChineseCharUnits[i]; return(true); } else { result = ChineseCharUnit.Empty; return(false); } }
private static ChineseCharUnit[] GetChineseCharUnits() { List<ChineseCharUnit> list = new List<ChineseCharUnit>(); using (MemoryStream stream = new MemoryStream(Resources.ChineseCharUnits)) { using (BinaryReader reader = new BinaryReader(stream)) { int length = reader.ReadInt32(); for (int i = 0; i < length; i++) { int pinyinsCount = reader.ReadByte(); ushort[] pinyins = new ushort[pinyinsCount]; for (int j = 0; j < pinyinsCount; j++) { pinyins[j] = reader.ReadUInt16(); } byte strokeNumber = reader.ReadByte(); char simplified = reader.ReadChar(); char traditional = reader.ReadChar(); ChineseCharUnit ch = new ChineseCharUnit(pinyins, strokeNumber, simplified, traditional); list.Add(ch); } reader.Close(); } } return list.ToArray(); }
/// <summary> /// 尝试获取表示中文汉字信息的 <see cref="ChineseCharUnit"/> 结构对象。如果传入的字符不是一个中文字符,则会获取失败。 /// 如果获取失败,则输出参数 <paramref name="result"/> 将会被设置为 <see cref="ChineseCharUnit.Empty"/>。 /// </summary> /// <param name="c"></param> /// <param name="result"></param> /// <returns></returns> public static bool TryGetCharUnit(char c, out ChineseCharUnit result) { int i = Array.BinarySearch(ChineseChars, c); if (i >= 0) { result = ChineseCharUnits[i]; return true; } else { result = ChineseCharUnit.Empty; return false; } }