示例#1
0
 /// <summary>
 /// <para>Returns information about a bunch of Hanzi.</para>
 /// <para>Accepts A-Z, 0-9. Returns null in array for other non-ideographs, and for unknown Hanzi.</para>
 /// </summary>
 public UniHanziInfo[] GetUnihanInfo(char[] chars)
 {
     UniHanziInfo[] res = new UniHanziInfo[chars.Length];
     using (BinReader br = new BinReader(dataFileName))
     {
         for (int i = 0; i != chars.Length; ++i)
         {
             char c = chars[i];
             // Character is an upper-case letter or a digit: itself
             if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z'))
             {
                 PinyinSyllable syll = new PinyinSyllable(c.ToString(), -1);
                 UniHanziInfo   uhi  = new UniHanziInfo(true, new char[] { c }, new PinyinSyllable[] { syll });
                 res[i] = uhi;
             }
             // Get genuine Hanzi info, if present
             else
             {
                 int cint = (int)c;
                 int pos  = 0;
                 if (cint < chrPoss.Length)
                 {
                     pos = chrPoss[cint];
                 }
                 if (pos == 0)
                 {
                     continue;
                 }
                 br.Position = pos;
                 byte flags = br.ReadByte();
                 if ((flags & 1) != 1)
                 {
                     continue;
                 }
                 res[i] = new UniHanziInfo(br);
             }
         }
     }
     return(res);
 }
示例#2
0
 public HanziStrokes GetStrokes(char c)
 {
     using (BinReader br = new BinReader(dataFileName))
     {
         int pos = chrPoss[(int)c];
         if (pos == 0)
         {
             return(null);
         }
         br.Position = pos;
         byte flags = br.ReadByte();
         if ((flags & 2) != 2)
         {
             return(null);
         }
         if ((flags & 1) == 1)
         {
             var trash = new UniHanziInfo(br);
         }
         return(new HanziStrokes(br));
     }
 }