Пример #1
0
        private void ReadData(ByteBuffer bytes)
        {
            // read the header
            ICUBinary.ReadHeader(bytes, FMT, new IsAcceptable());

            // read indexes[]
            int i, count;

            count = bytes.GetInt32();
            if (count < IX_TOP)
            {
                throw new IOException("indexes[0] too small in " + DATA_FILE_NAME);
            }
            indexes = new int[count];

            indexes[0] = count;
            for (i = 1; i < count; ++i)
            {
                indexes[i] = bytes.GetInt32();
            }

            // read the trie
            trie = Trie2_16.CreateFromSerialized(bytes);
            int expectedTrieLength = indexes[IX_TRIE_SIZE];
            int trieLength         = trie.SerializedLength;

            if (trieLength > expectedTrieLength)
            {
                throw new IOException(DATA_FILE_NAME + ": not enough bytes for the trie");
            }
            // skip padding after trie bytes
            ICUBinary.SkipBytes(bytes, expectedTrieLength - trieLength);

            // read mirrors[]
            count = indexes[IX_MIRROR_LENGTH];
            if (count > 0)
            {
                mirrors = ICUBinary.GetInt32s(bytes, count, 0);
            }

            // read jgArray[]
            count   = indexes[IX_JG_LIMIT] - indexes[IX_JG_START];
            jgArray = new byte[count];
            bytes.Get(jgArray);

            // read jgArray2[]
            count    = indexes[IX_JG_LIMIT2] - indexes[IX_JG_START2];
            jgArray2 = new byte[count];
            bytes.Get(jgArray2);
        }
Пример #2
0
        /// <summary>
        /// Private constructor.
        /// </summary>
        /// <param name="bytes">ICU StringPrep data file buffer.</param>
        /// <exception cref="System.IO.IOException">If data file fails authentication.</exception>
        public StringPrepDataReader(ByteBuffer bytes)
        {
            if (debug)
            {
                Console.Out.WriteLine("Bytes in buffer " + bytes.Remaining);
            }

            byteBuffer     = bytes;
            unicodeVersion = ICUBinary.ReadHeader(byteBuffer, DATA_FORMAT_ID, this);

            if (debug)
            {
                Console.Out.WriteLine("Bytes left in byteBuffer " + byteBuffer.Remaining);
            }
        }
Пример #3
0
        private void ReadData(ByteBuffer bytes)
        {
            // read the header
            ICUBinary.ReadHeader(bytes, FMT, new IsAcceptable());

            // read indexes[]
            int count = bytes.GetInt32();

            if (count < IX_TOP)
            {
                throw new IOException("indexes[0] too small in " + DATA_FILE_NAME);
            }
            indexes = new int[count];

            indexes[0] = count;
            for (int i = 1; i < count; ++i)
            {
                indexes[i] = bytes.GetInt32();
            }

            // read the trie
            trie = Trie2_16.CreateFromSerialized(bytes);
            int expectedTrieLength = indexes[IX_TRIE_SIZE];
            int trieLength         = trie.GetSerializedLength();

            if (trieLength > expectedTrieLength)
            {
                throw new IOException(DATA_FILE_NAME + ": not enough bytes for the trie");
            }
            // skip padding after trie bytes
            ICUBinary.SkipBytes(bytes, expectedTrieLength - trieLength);

            // read exceptions[]
            count = indexes[IX_EXC_LENGTH];
            if (count > 0)
            {
                exceptions = ICUBinary.GetString(bytes, count, 0);
            }

            // read unfold[]
            count = indexes[IX_UNFOLD_LENGTH];
            if (count > 0)
            {
                unfold = ICUBinary.GetChars(bytes, count, 0);
            }
        }
Пример #4
0
        private const int DATA_FORMAT = 0x706E616D;  // "pnam"

        private void Load(ByteBuffer bytes)
        {
            //dataVersion=ICUBinary.readHeaderAndDataVersion(bytes, DATA_FORMAT, IS_ACCEPTABLE);
            ICUBinary.ReadHeader(bytes, DATA_FORMAT, IS_ACCEPTABLE);
            int indexesLength = bytes.GetInt32() / 4;  // inIndexes[IX_VALUE_MAPS_OFFSET]/4

            if (indexesLength < 8)
            {  // formatVersion 2 initially has 8 indexes
                throw new IOException("pnames.icu: not enough indexes");
            }
            int[]
            inIndexes = new int[indexesLength];
            inIndexes[0] = indexesLength * 4;
            for (int i = 1; i < indexesLength; ++i)
            {
                inIndexes[i] = bytes.GetInt32();
            }

            // Read the valueMaps.
            int offset     = inIndexes[IX_VALUE_MAPS_OFFSET];
            int nextOffset = inIndexes[IX_BYTE_TRIES_OFFSET];
            int numInts    = (nextOffset - offset) / 4;

            valueMaps = ICUBinary.GetInt32s(bytes, numInts, 0);

            // Read the bytesTries.
            offset     = nextOffset;
            nextOffset = inIndexes[IX_NAME_GROUPS_OFFSET];
            int numBytes = nextOffset - offset;

            bytesTries = new byte[numBytes];
            bytes.Get(bytesTries);

            // Read the nameGroups and turn them from ASCII bytes into a .NET string.
            offset     = nextOffset;
            nextOffset = inIndexes[IX_RESERVED3_OFFSET];
            numBytes   = nextOffset - offset;
            StringBuilder sb = new StringBuilder(numBytes);

            for (int i = 0; i < numBytes; ++i)
            {
                sb.Append((char)bytes.Get());
            }
            nameGroups = sb.ToString();
        }
Пример #5
0
        // protected constructor ---------------------------------------------

        /// <summary>
        /// Protected constructor.
        /// </summary>
        /// <param name="bytes">ICU uprop.dat file buffer.</param>
        /// <exception cref="IOException">If data file fails authentication.</exception>
        internal UCharacterNameReader(ByteBuffer bytes)
        {
            ICUBinary.ReadHeader(bytes, DATA_FORMAT_ID_, this);
            m_byteBuffer_ = bytes;
        }