Example #1
0
        public StarDictIdx(StarDictInfo info, Encoding enc = null)
        {
            this.encoding   = enc ?? Encoding.UTF8;
            this.offsetSize = info.PointerSize;

            var fname = info.BaseName + ".idx";

            if (File.Exists(fname))
            {
                this.table = new TxtHeteroIdxTable(fname, this.MeasureEntryLength);
            }
            else
            {
                this.table = new StrHeteroIdxTable(fname + ".gz", this.MeasureEntryLength);
            }

            // create and populate the index of index
            this.indexIndex = new int[info.NumberOfEntries + 1];
            for (int cnt = 1, offset = 0; cnt < info.NumberOfEntries; ++cnt)
            {
                this.indexIndex[cnt] = offset = this.table.FindNext(offset);
            }

            this.indexIndex[info.NumberOfEntries] = info.IndexFileSize; // last sentry
        }
Example #2
0
 private int MeasureEntryLength(HeteroIdxTable tbl)
 {
     for (var cnt = 0;; ++cnt)
     {
         if (tbl.ReadByte() == 0)
         {
             return(cnt + 1 + this.AddressSize); // '\0' + sizeof(offsetPtr) + 4 bytes size
         }
     }
 }