Пример #1
0
        /// <summary>
        /// Returns a <see cref="Normalizer2"/> instance which uses the specified data file
        /// (an ICU data file if data=null, or else custom binary data)
        /// and which composes or decomposes text according to the specified mode.
        /// Returns an unmodifiable singleton instance.
        /// <list type="bullet">
        ///		<item><description>Use data=null for data files that are part of ICU's own data.</description></item>
        ///		<item><description>Use name="nfc" and COMPOSE/DECOMPOSE for Unicode standard NFC/NFD.</description></item>
        ///		<item><description>Use name="nfkc" and COMPOSE/DECOMPOSE for Unicode standard NFKC/NFKD.</description></item>
        ///		<item><description>Use name="nfkc_cf" and COMPOSE for Unicode standard NFKC_CF=NFKC_Casefold.</description></item>
        /// </list>
        /// <para/>
        /// If data!=null, then the binary data is read once and cached using the provided
        /// name as the key.
        /// If you know or expect the data to be cached already, you can use data!=null
        /// for non-ICU data as well.
        /// </summary>
        /// <param name="data">The binary, big-endian normalization (.nrm file) data, or null for ICU data.</param>
        /// <param name="name">"nfc" or "nfkc" or "nfkc_cf" or name of custom data file.</param>
        /// <param name="mode">Normalization mode (compose or decompose etc.)</param>
        /// <returns>The requested <see cref="Normalizer2"/>, if successful.</returns>
        public static Normalizer2 GetInstance(Stream data, string name, Normalizer2Mode mode)
        {
            ByteBuffer bytes = null;

            if (data != null)
            {
                try
                {
                    bytes = ICUBinary.GetByteBufferFromStreamAndDisposeStream(data);
                }
                catch (IOException e)
                {
                    throw new ICUUncheckedIOException(e);
                }
            }
            Norm2AllModes all2Modes = Norm2AllModes.GetInstance(bytes, name);

            switch (mode)
            {
            case Normalizer2Mode.Compose: return(all2Modes.Comp);

            case Normalizer2Mode.Decompose: return(all2Modes.Decomp);

            case Normalizer2Mode.FCD: return(all2Modes.Fcd);

            case Normalizer2Mode.ComposeContiguous: return(all2Modes.Fcc);

            default: return(null);     // will not occur
            }
        }
Пример #2
0
        // Was testTrieRanges in ICU4C.  Renamed to not conflict with ICU4J test framework.
        private void checkTrieRanges(String testName, String serializedName, bool withClone,
                                     int[][] setRanges, int[][] checkRanges)
        {
            string ns =
#if FEATURE_TYPEEXTENSIONS_GETTYPEINFO
                typeof(Trie2Test).GetTypeInfo().Namespace;
#else
                typeof(Trie2Test).Namespace;
#endif

            // Run tests against Tries that were built by ICU4C and serialized.
            String fileName16 = ns + ".Trie2Test." + serializedName + ".16.tri2";
            String fileName32 = ns + ".Trie2Test." + serializedName + ".32.tri2";

#if FEATURE_TYPEEXTENSIONS_GETTYPEINFO
            Assembly assembly = typeof(Trie2Test).GetTypeInfo().Assembly;
#else
            Assembly assembly = typeof(Trie2Test).Assembly;
#endif

            Stream @is = assembly.GetManifestResourceStream(fileName16);
            Trie2  trie16;
            try
            {
                trie16 = Trie2.CreateFromSerialized(ICUBinary.GetByteBufferFromStreamAndDisposeStream(@is));
            }
            finally
            {
                @is.Dispose();
            }
            trieGettersTest(testName, trie16, checkRanges);

            @is = assembly.GetManifestResourceStream(fileName32);
            Trie2 trie32;
            try
            {
                trie32 = Trie2.CreateFromSerialized(ICUBinary.GetByteBufferFromStreamAndDisposeStream(@is));
            }
            finally
            {
                @is.Dispose();
            }
            trieGettersTest(testName, trie32, checkRanges);

            // Run the same tests against locally contructed Tries.
            Trie2Writable trieW = genTrieFromSetRanges(setRanges);
            trieGettersTest(testName, trieW, checkRanges);
            assertEquals("", trieW, trie16);   // Locally built tries must be
            assertEquals("", trieW, trie32);   //   the same as those imported from ICU4C


            Trie2_32 trie32a = trieW.ToTrie2_32();
            trieGettersTest(testName, trie32a, checkRanges);

            Trie2_16 trie16a = trieW.ToTrie2_16();
            trieGettersTest(testName, trie16a, checkRanges);
        }
Пример #3
0
 /// <summary>
 /// Creates an <see cref="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 <see cref="StringPrep"/> profile binarySun.</param>
 /// <exception cref="IOException">An exception occurs when I/O of the inputstream is invalid.</exception>
 /// <stable>ICU 2.8</stable>
 public StringPrep(Stream inputStream)
     : this(ICUBinary.GetByteBufferFromStreamAndDisposeStream(inputStream))
 {
     // TODO: Add a public constructor that takes ByteBuffer directly.
 }