Beispiel #1
0
        /// <summary>
        /// Ctor: serialize from binary.
        /// </summary>
        public UniHanziInfo(BinReader br)
        {
            byte b = br.ReadByte();

            if (b == 0)
            {
                CanBeSimp = false;
            }
            else
            {
                CanBeSimp = true;
            }
            b            = br.ReadByte();
            TradVariants = new char[b];
            for (byte i = 0; i != b; ++i)
            {
                TradVariants[i] = br.ReadChar();
            }
            b      = br.ReadByte();
            Pinyin = new PinyinSyllable[b];
            for (byte i = 0; i != b; ++i)
            {
                Pinyin[i] = new PinyinSyllable(br);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Static creator: deserialize instance from binary stream.
        /// </summary>
        public static HybridText Deserialize(BinReader br)
        {
            // Read number of runs
            short length = br.ReadShort();

            // Zero runs: return one and only "empty" object
            if (length == 0)
            {
                return(Empty);
            }

            // OK, deserialize runs.
            List <TextRun> runs = new List <TextRun>(length);

            // Deserialize each run after looking at flags for polymorphism
            for (short i = 0; i != length; ++i)
            {
                byte    flags = br.ReadByte();
                bool    isZho = ((flags & 1) == 1);
                TextRun tr;
                if (isZho)
                {
                    tr = new TextRunZho(br);
                }
                else
                {
                    tr = new TextRunLatin(br);
                }
                runs.Add(tr);
            }
            // Done
            return(new HybridText(new ReadOnlyCollection <TextRun>(runs)));
        }
Beispiel #3
0
        /// <summary>
        /// Ctor: deserialize from binary stream.
        /// </summary>
        public CedictEntry(BinReader br)
        {
            pinyin         = br.ReadArray(brr => new PinyinSyllable(brr));
            ChSimpl        = br.ReadString();
            ChTrad         = br.ReadString();
            Freq           = br.ReadUShort();
            StableId       = br.ReadInt();
            Status         = (EntryStatus)br.ReadByte();
            senses         = br.ReadArray(brr => new CedictSense(brr));
            hanziPinyinMap = br.ReadArray(brr => brr.ReadShort());
            short cnt = br.ReadShort();

            if (cnt == 0)
            {
                zhoEmbeds = null;
            }
            else
            {
                zhoEmbeds = new ZhoEmbedding[cnt];
                for (int i = 0; i != cnt; ++i)
                {
                    zhoEmbeds[i] = new ZhoEmbedding(br);
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Ctor: deserialize from binary stream.
        /// </summary>
        public PinyinSyllable(BinReader br)
        {
            Text = br.ReadString();
            byte b = br.ReadByte();

            Tone = ((int)b) - 1;
        }
Beispiel #5
0
        /// <summary>
        /// Ctor: read from binary stream.
        /// </summary>
        public TextRunZho(BinReader br)
        {
            // Read flags
            // 1: Traditional and simplified are different
            // 2: Pinyin present
            byte flags = br.ReadByte();

            // Read simplified
            if ((flags & 1) == 1)
            {
                Simp = br.ReadString();
            }
            // Is traditional different?
            if ((flags & 2) == 2)
            {
                Trad = br.ReadString();
            }
            else
            {
                Trad = Simp;
            }
            // Is pinyin present?
            if ((flags & 4) == 4)
            {
                int pinyinCount = (int)br.ReadByte();
                Pinyin = new PinyinSyllable[pinyinCount];
                for (int i = 0; i != pinyinCount; ++i)
                {
                    Pinyin[i] = new PinyinSyllable(br);
                }
            }
            else
            {
                Pinyin = null;
            }
        }