Example #1
0
        private StringPrep(ByteBuffer bytes)
        {
            StringPrepDataReader reader = new StringPrepDataReader(bytes);

            // read the indexes
            indexes = reader.ReadIndexes(INDEX_TOP);

            sprepTrie = new CharTrie(bytes, null);

            //indexes[INDEX_MAPPING_DATA_SIZE] store the size of mappingData in bytes
            // load the rest of the data data and initialize the data members
            mappingData = reader.Read(indexes[INDEX_MAPPING_DATA_SIZE] / 2);

            // get the options
            doNFKC      = ((indexes[OPTIONS] & NORMALIZATION_ON) > 0);
            checkBiDi   = ((indexes[OPTIONS] & CHECK_BIDI_ON) > 0);
            sprepUniVer = GetVersionInfo(reader.GetUnicodeVersion());
            normCorrVer = GetVersionInfo(indexes[NORM_CORRECTNS_LAST_UNI_VERSION]);
            VersionInfo normUniVer = UCharacter.UnicodeVersion;

            if (normUniVer.CompareTo(sprepUniVer) < 0 &&    /* the Unicode version of SPREP file must be less than the Unicode Vesion of the normalization data */
                normUniVer.CompareTo(normCorrVer) < 0 &&    /* the Unicode version of the NormalizationCorrections.txt file should be less than the Unicode Vesion of the normalization data */
                ((indexes[OPTIONS] & NORMALIZATION_ON) > 0) /* normalization turned on*/
                )
            {
                throw new IOException("Normalization Correction version not supported");
            }

            if (checkBiDi)
            {
                bdp = UBiDiProps.Instance;
            }
        }
Example #2
0
        /// <summary>
        /// Creates an StringPrep object after reading the input stream. The object
        /// does not hold a reference to the input steam, so the stream can be closed
        /// after the method returns.
        /// </summary>
        ///
        /// <param name="inputStream">The stream for reading the StringPrep profile binarySun</param>
        /// <exception cref="IOException"></exception>
        /// @stable ICU 2.8
        public StringPrep(Stream inputStream)
        {
            BufferedStream b = new BufferedStream(inputStream, DATA_BUFFER_SIZE);

            StringPrepDataReader reader = new StringPrepDataReader(b);

            // read the indexes
            indexes = reader.ReadIndexes(INDEX_TOP);

            byte[] sprepBytes = new byte[indexes[INDEX_TRIE_SIZE]];

            // indexes[INDEX_MAPPING_DATA_SIZE] store the size of mappingData in
            // bytes
            mappingData = new char[indexes[INDEX_MAPPING_DATA_SIZE] / 2];
            // load the rest of the data data and initialize the data members
            reader.Read(sprepBytes, mappingData);

            throw new Exception("Missing code");
            // sprepTrie = new CharTrie(sprepBytes, null);

            // get the data format version
            /* formatVersion = */ reader.GetDataFormatVersion();

            // get the options
            doNFKC      = ((indexes[OPTIONS] & NORMALIZATION_ON) > 0);
            checkBiDi   = ((indexes[OPTIONS] & CHECK_BIDI_ON) > 0);
            sprepUniVer = GetVersionInfo(reader.GetUnicodeVersion());
            normCorrVer = GetVersionInfo(indexes[NORM_CORRECTNS_LAST_UNI_VERSION]);
            VersionInfo normUniVer = IBM.ICU.Text.Normalizer.GetUnicodeVersion();

            if (normUniVer.CompareTo(sprepUniVer) < 0 &&    /*
                                                             * the Unicode version of
                                                             * SPREP file must be less
                                                             * than the Unicode Vesion
                                                             * of the normalization
                                                             * data
                                                             */
                normUniVer.CompareTo(normCorrVer) < 0 &&    /*
                                                             * the Unicode version of the
                                                             * NormalizationCorrections.txt
                                                             * file should be less than the
                                                             * Unicode Vesion of the
                                                             * normalization data
                                                             */
                ((indexes[OPTIONS] & NORMALIZATION_ON) > 0) /* normalization turned on */
                )
            {
                throw new IOException(
                          "Normalization Correction version not supported");
            }
            b.Close();

            if (checkBiDi)
            {
                bdp = IBM.ICU.Impl.UBiDiProps.GetSingleton();
            }
        }