XDictEntry ParseEntry(BglBlock block) { int len = 0; int pos = 0; // Head len = block.Data[pos++]; String headWord = block.GetString(pos, len, SrcEncoding); pos += len; // Definition len = block.Data[pos++] << 8 | block.Data[pos++]; String def = block.GetDefString(pos, len, DstEncoding); pos += len; // Alternates List <string> alternates = new List <string>(); while (pos < block.Length) { len = block.Data[pos++]; String alternate = block.GetString(pos, len, SrcEncoding); pos += len; alternates.Add(alternate); } return(CreateEntry(headWord, def, alternates)); }
void ParseUnzipped(Stream s, XDict dict) { while (true) { BglBlock block = BglBlock.Read(s); if (block == null) { break; } if (block.Type == 1 || block.Type == 10) { XDictEntry e = ParseEntry(block); dict.AddEntry(e); } } }
public static BglBlock Read(Stream s) { BglBlock block = new BglBlock(); block.Length = BabylonBglParser.ReadNum(s, 1); block.Type = block.Length & 0xF; if (block.Type == 4) { return(null); } // end-of-file marker block.Length >>= 4; block.Length = block.Length < 4 ? BabylonBglParser.ReadNum(s, block.Length + 1) : block.Length - 4; if (block.Length > 0) { block.Data = new byte[block.Length]; s.Read(block.Data, 0, block.Data.Length); } return(block); }
//---------------------------------------------- void parseMetaData(Stream s) { string headword = string.Empty; int type = -1; while (true) { headword = string.Empty; BglBlock block = BglBlock.Read(s); if (block == null) { break; } if (block.Type == 0 && block.Data[0] == 8) { type = block.Data[1]; if (type > 64) { type -= 65; } this.DefCharset = BabylonConsts.Bgl_charset[type]; } else if (block.Type == 3) { int pos = 2; switch (block.Data[1]) { case 1: for (int a = 0; a < block.Length - 2; a++) { headword += (char)block.Data[pos++]; } this.Title = headword; break; case 2: for (int a = 0; a < block.Length - 2; a++) { headword += (char)block.Data[pos++]; } this.Author = headword; break; case 7: this.SrcLng = BabylonConsts.Bgl_language[block.Data[5]]; break; case 8: this.DstLng = BabylonConsts.Bgl_language[block.Data[5]]; break; case 26: type = block.Data[2]; if (type > 64) { type -= 65; } this.SrcEnc = BabylonConsts.Bgl_charset[type]; this.SrcEncName = BabylonConsts.Bgl_charsetname[type]; break; case 27: type = block.Data[2]; if (type > 64) { type -= 65; } this.DstEnc = BabylonConsts.Bgl_charset[type]; this.DstEncName = BabylonConsts.Bgl_charsetname[type]; break; } } else { continue; } } }
public static BglBlock Read(Stream s) { BglBlock block = new BglBlock(); block.Length = BabylonBglParser.ReadNum(s, 1); block.Type = block.Length & 0xF; if (block.Type == 4) { return null; } // end-of-file marker block.Length >>= 4; block.Length = block.Length < 4 ? BabylonBglParser.ReadNum(s, block.Length + 1) : block.Length - 4; if (block.Length > 0) { block.Data = new byte[block.Length]; s.Read(block.Data, 0, block.Data.Length); } return block; }
XDictEntry ParseEntry(BglBlock block) { int len = 0; int pos = 0; // Head len = block.Data[pos++]; String headWord = block.GetString(pos, len, SrcEncoding); pos += len; // Definition len = block.Data[pos++] << 8 | block.Data[pos++]; String def = block.GetDefString(pos, len, DstEncoding); pos += len; // Alternates List<string> alternates = new List<string>(); while (pos < block.Length) { len = block.Data[pos++]; String alternate = block.GetString(pos, len, SrcEncoding); pos += len; alternates.Add(alternate); } return CreateEntry(headWord, def, alternates); }