Esempio n. 1
0
        // protected methods -------------------------------------------------

        /// <summary>
        /// Read and break up the stream of data passed in as arguments and fills up
        /// UCharacterName. If unsuccessful false will be returned.
        /// </summary>
        ///
        /// <param name="data">instance of datablock</param>
        /// <exception cref="IOException">thrown when there's a data error.</exception>
        protected internal void Read(UCharacterName data)
        {
            // reading index
            m_tokenstringindex_ = m_dataInputStream_.ReadInt();
            m_groupindex_       = m_dataInputStream_.ReadInt();
            m_groupstringindex_ = m_dataInputStream_.ReadInt();
            m_algnamesindex_    = m_dataInputStream_.ReadInt();

            // reading tokens
            int count = m_dataInputStream_.ReadChar();

            char[] token = new char[count];
            for (char i = (char)(0); i < count; i++)
            {
                token[i] = m_dataInputStream_.ReadChar();
            }
            int size = m_groupindex_ - m_tokenstringindex_;

            byte[] tokenstr = new byte[size];
            m_dataInputStream_.ReadFully(tokenstr);
            data.SetToken(token, tokenstr);

            // reading the group information records
            count = m_dataInputStream_.ReadChar();
            data.SetGroupCountSize(count, GROUP_INFO_SIZE_);
            count *= GROUP_INFO_SIZE_;
            char[] group = new char[count];
            for (int i_0 = 0; i_0 < count; i_0++)
            {
                group[i_0] = m_dataInputStream_.ReadChar();
            }

            size = m_algnamesindex_ - m_groupstringindex_;
            byte[] groupstring = new byte[size];
            m_dataInputStream_.ReadFully(groupstring);

            data.SetGroup(group, groupstring);

            count = m_dataInputStream_.ReadInt();
            UCharacterName.AlgorithmName[] alg = new UCharacterName.AlgorithmName[count];

            for (int i_1 = 0; i_1 < count; i_1++)
            {
                UCharacterName.AlgorithmName an = ReadAlg();
                if (an == null)
                {
                    throw new IOException(
                              "unames.icu read error: Algorithmic names creation error");
                }
                alg[i_1] = an;
            }
            data.SetAlgorithm(alg);
        }
Esempio n. 2
0
        // private methods ---------------------------------------------------

        /// <summary>
        /// Reads an individual record of AlgorithmNames
        /// </summary>
        ///
        /// <returns>an instance of AlgorithNames if read is successful otherwise null</returns>
        /// <exception cref="IOException">thrown when file read error occurs or data is corrupted</exception>
        private UCharacterName.AlgorithmName ReadAlg()
        {
            UCharacterName.AlgorithmName result = new UCharacterName.AlgorithmName();
            int   rangestart = m_dataInputStream_.ReadInt();
            int   rangeend   = m_dataInputStream_.ReadInt();
            sbyte type       = m_dataInputStream_.ReadByte();
            sbyte variant    = m_dataInputStream_.ReadByte();

            if (!result.SetInfo(rangestart, rangeend, type, variant))
            {
                return(null);
            }

            int size = m_dataInputStream_.ReadChar();

            if (type == IBM.ICU.Impl.UCharacterName.AlgorithmName.TYPE_1_)
            {
                char[] factor = new char[variant];
                for (int j = 0; j < variant; j++)
                {
                    factor[j] = m_dataInputStream_.ReadChar();
                }

                result.SetFactor(factor);
                size -= (variant << 1);
            }

            StringBuilder prefix = new StringBuilder();
            char          c      = (char)(m_dataInputStream_.ReadByte() & 0x00FF);

            while (c != 0)
            {
                prefix.Append(c);
                c = (char)(m_dataInputStream_.ReadByte() & 0x00FF);
            }

            result.SetPrefix(prefix.ToString());

            size -= (ALG_INFO_SIZE_ + prefix.Length + 1);

            if (size > 0)
            {
                byte[] str0 = new byte[size];
                m_dataInputStream_.ReadFully(str0);
                result.SetFactorString(str0);
            }
            return(result);
        }
Esempio n. 3
0
        // protected methods -------------------------------------------------

        /// <summary>
        /// Read and break up the stream of data passed in as arguments
        /// and fills up <see cref="UCharacterName"/>.
        /// If unsuccessful false will be returned.
        /// </summary>
        /// <param name="data">Instance of datablock.</param>
        /// <exception cref="IOException">Thrown when there's a data error.</exception>
        internal void Read(UCharacterName data)
        {
            // reading index
            m_tokenstringindex_ = m_byteBuffer_.GetInt32();
            m_groupindex_       = m_byteBuffer_.GetInt32();
            m_groupstringindex_ = m_byteBuffer_.GetInt32();
            m_algnamesindex_    = m_byteBuffer_.GetInt32();

            // reading tokens
            int count = m_byteBuffer_.GetChar();

            char[] token = ICUBinary.GetChars(m_byteBuffer_, count, 0);
            int    size  = m_groupindex_ - m_tokenstringindex_;

            byte[] tokenstr = new byte[size];
            m_byteBuffer_.Get(tokenstr);
            data.SetToken(token, tokenstr);

            // reading the group information records
            count = m_byteBuffer_.GetChar();
            data.SetGroupCountSize(count, GROUP_INFO_SIZE_);
            count *= GROUP_INFO_SIZE_;
            char[] group = ICUBinary.GetChars(m_byteBuffer_, count, 0);

            size = m_algnamesindex_ - m_groupstringindex_;
            byte[] groupstring = new byte[size];
            m_byteBuffer_.Get(groupstring);

            data.SetGroup(group, groupstring);

            count = m_byteBuffer_.GetInt32();
            UCharacterName.AlgorithmName[] alg =
                new UCharacterName.AlgorithmName[count];

            for (int i = 0; i < count; i++)
            {
                UCharacterName.AlgorithmName an = ReadAlg();
                if (an == null)
                {
                    throw new IOException("unames.icu read error: Algorithmic names creation error");
                }
                alg[i] = an;
            }
            data.SetAlgorithm(alg);
        }
Esempio n. 4
0
        // private methods ---------------------------------------------------

        /// <summary>
        /// Reads an individual record of <see cref="UCharacterName.AlgorithmName"/>s
        /// </summary>
        /// <returns>An instance of <see cref="UCharacterName.AlgorithmName"/>s if read is successful otherwise null.</returns>
        /// <exception cref="IOException">Thrown when file read error occurs or data is corrupted.</exception>
        private UCharacterName.AlgorithmName ReadAlg()
        {
            UCharacterName.AlgorithmName result =
                new UCharacterName.AlgorithmName();
            int  rangestart = m_byteBuffer_.GetInt32();
            int  rangeend   = m_byteBuffer_.GetInt32();
            byte type       = m_byteBuffer_.Get();
            byte variant    = m_byteBuffer_.Get();

            if (!result.SetInfo(rangestart, rangeend, type, variant))
            {
                return(null);
            }

            int size = m_byteBuffer_.GetChar();

            if (type == UCharacterName.AlgorithmName.TYPE_1_)
            {
                char[] factor = ICUBinary.GetChars(m_byteBuffer_, variant, 0);

                result.SetFactor(factor);
                size -= (variant << 1);
            }

            StringBuilder prefix = new StringBuilder();
            char          c      = (char)(m_byteBuffer_.Get() & 0x00FF);

            while (c != 0)
            {
                prefix.Append(c);
                c = (char)(m_byteBuffer_.Get() & 0x00FF);
            }

            result.SetPrefix(prefix.ToString());

            size -= (ALG_INFO_SIZE_ + prefix.Length + 1);

            if (size > 0)
            {
                byte[] str = new byte[size];
                m_byteBuffer_.Get(str);
                result.SetFactorString(str);
            }
            return(result);
        }