Represents formatted unicode string in SST
Ejemplo n.º 1
0
        /// <summary>
        /// Reads strings from BIFF stream into SST array
        /// </summary>
        public void ReadStrings() {
            uint offset=(uint)m_readoffset+8;
            uint last=(uint)m_readoffset+RecordSize;
            int lastcontinue=0;
            uint count=UniqueCount;
            while (offset<last) {
                var str=new XlsFormattedUnicodeString(m_bytes, offset);
                uint prefix=str.HeadSize;
                uint postfix=str.TailSize;
                uint len=str.CharacterCount;
                uint size=prefix+postfix+len+((str.IsMultiByte)?len:0);
                if (offset+size>last) {
                    if (lastcontinue>=continues.Count) {
                        break;
                    }

                    uint contoffset=continues[lastcontinue];
                    byte encoding=Buffer.GetByte(m_bytes, (int)contoffset+4);
                    var buff=new byte[size*2];
                    Buffer.BlockCopy(m_bytes, (int)offset, buff, 0, (int)(last-offset));
                    if (encoding==0&&str.IsMultiByte) {
                        len-=(last-prefix-offset)/2;
                        string temp=ExcelToolKit.Extension.DefaultEncoding().GetString(m_bytes, (int)contoffset+5, (int)len);
                        byte[] tempbytes=Encoding.Unicode.GetBytes(temp);
                        Buffer.BlockCopy(tempbytes, 0, buff, (int)(last-offset), tempbytes.Length);
                        Buffer.BlockCopy(m_bytes, (int)(contoffset+5+len), buff, (int)(last-offset+len+len),
                                         (int)postfix);
                        offset=contoffset+5+len+postfix;
                    } else if (encoding==1&&str.IsMultiByte==false) {
                        len-=(last-offset-prefix);
                        string temp=Encoding.Unicode.GetString(m_bytes,
                                                                 (int)contoffset+5,
                                                                 (int)(len+len));
                        byte[] tempbytes=ExcelToolKit.Extension.DefaultEncoding().GetBytes(temp);
                        Buffer.BlockCopy(tempbytes, 0, buff, (int)(last-offset), tempbytes.Length);
                        Buffer.BlockCopy(m_bytes, (int)(contoffset+5+len+len), buff, (int)(last-offset+len),
                                         (int)postfix);
                        offset=contoffset+5+len+len+postfix;
                    } else {
                        Buffer.BlockCopy(m_bytes, (int)contoffset+5, buff, (int)(last-offset),
                                         (int)(size-last+offset));
                        offset=contoffset+5+size-last+offset;
                    }
                    last=contoffset+4+BitConverter.ToUInt16(m_bytes, (int)contoffset+2);
                    lastcontinue++;

                    str=new XlsFormattedUnicodeString(buff, 0);
                } else {
                    offset+=size;
                    if (offset==last) {
                        if (lastcontinue<continues.Count) {
                            uint contoffset=continues[lastcontinue];
                            offset=contoffset+4;
                            last=offset+BitConverter.ToUInt16(m_bytes, (int)contoffset+2);
                            lastcontinue++;
                        } else {
                            count=1;
                        }
                    }
                }
                m_strings.Add(str.Value);
                count--;
                if (count==0) {
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads strings from BIFF stream into SST array
        /// </summary>
        public void ReadStrings()
        {
            uint offset       = (uint)m_readoffset + 8;
            uint last         = (uint)m_readoffset + RecordSize;
            int  lastcontinue = 0;
            uint count        = UniqueCount;

            while (offset < last)
            {
                XlsFormattedUnicodeString str = new XlsFormattedUnicodeString(m_bytes, offset);
                uint prefix  = str.HeadSize;
                uint postfix = str.TailSize;
                uint len     = str.CharacterCount;
                uint size    = prefix + postfix + len + ((str.IsMultiByte) ? len : 0);
                if (offset + size > last)
                {
                    if (lastcontinue >= continues.Count)
                    {
                        break;
                    }

                    uint   contoffset = continues[lastcontinue];
                    byte   encoding   = Buffer.GetByte(m_bytes, (int)contoffset + 4);
                    byte[] buff       = new byte[size * 2];
                    Buffer.BlockCopy(m_bytes, (int)offset, buff, 0, (int)(last - offset));
                    if (encoding == 0 && str.IsMultiByte)
                    {
                        len -= (last - prefix - offset) / 2;
                        string temp      = Encoding.Default.GetString(m_bytes, (int)contoffset + 5, (int)len);
                        byte[] tempbytes = Encoding.Unicode.GetBytes(temp);
                        Buffer.BlockCopy(tempbytes, 0, buff, (int)(last - offset), tempbytes.Length);
                        Buffer.BlockCopy(m_bytes, (int)(contoffset + 5 + len), buff, (int)(last - offset + len + len), (int)postfix);
                        offset = contoffset + 5 + len + postfix;
                    }
                    else if (encoding == 1 && str.IsMultiByte == false)
                    {
                        len -= (last - offset - prefix);
                        string temp = Encoding.Unicode.GetString(m_bytes,
                                                                 (int)contoffset + 5,
                                                                 (int)(len + len));
                        byte[] tempbytes = Encoding.Default.GetBytes(temp);
                        Buffer.BlockCopy(tempbytes, 0, buff, (int)(last - offset), tempbytes.Length);
                        Buffer.BlockCopy(m_bytes, (int)(contoffset + 5 + len + len), buff, (int)(last - offset + len), (int)postfix);
                        offset = contoffset + 5 + len + len + postfix;
                    }
                    else
                    {
                        Buffer.BlockCopy(m_bytes, (int)contoffset + 5, buff, (int)(last - offset), (int)(size - last + offset));
                        offset = contoffset + 5 + size - last + offset;
                    }
                    last = contoffset + 4 + BitConverter.ToUInt16(m_bytes, (int)contoffset + 2);
                    lastcontinue++;

                    str = new XlsFormattedUnicodeString(buff, 0);
                }
                else
                {
                    offset += size;
                    if (offset == last)
                    {
                        if (lastcontinue < continues.Count)
                        {
                            uint contoffset = continues[lastcontinue];
                            offset = contoffset + 4;
                            last   = offset + BitConverter.ToUInt16(m_bytes, (int)contoffset + 2);
                            lastcontinue++;
                        }
                        else
                        {
                            count = 1;
                        }
                    }
                }
                m_strings.Add(str.Value);
                count--;
                if (count == 0)
                {
                    break;
                }
            }
        }