Esempio n. 1
0
        public void TestWordNextWithInt()
        {
            BreakIterator bi = GetWordInstance(CultureInfo.InvariantCulture);

            bi.SetText(TEXT);

            int temp;

            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(0, temp);
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(6, temp);


            temp = bi.Next(10);
            Console.WriteLine(temp);
            assertEquals(23, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(23, temp);
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(39, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(39, temp);
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(40, temp);
            temp = bi.Next(-8);     // Test going backward
            Console.WriteLine(temp);
            assertEquals(16, temp); // Magically, this is correct (from position 28 back 8 places) in Java, even though its start position is wrong
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(17, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(17, temp);


            temp = bi.Next(107); // Go past the last boundary
            Console.WriteLine(temp);
            assertEquals(-1, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(107, temp);
            temp = bi.Next(-107); // Go past the first boundary
            Console.WriteLine(temp);
            assertEquals(-1, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(0, temp);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a <see cref="BreakIterator"/> that breaks on hyphens
        /// similar to the JDK, but otherwise has the default word break functionality
        /// described at <a href="http://userguide.icu-project.org/boundaryanalysis">http://userguide.icu-project.org/boundaryanalysis</a>.
        /// </summary>
        /// <remarks>
        /// NOTE: If the culture is Thai, Lao, Burmese, Khmer, Japanese, Korean, or Chinese,
        /// the instance returned has the same dictionary-based <see cref="BreakIterator"/> behavior
        /// as if you call <see cref="BreakIterator.GetWordInstance(CultureInfo)"/>. See the
        /// section titled "Details about Dictionary-Based Break Iteration" at
        /// <a href="http://userguide.icu-project.org/boundaryanalysis">http://userguide.icu-project.org/boundaryanalysis</a>.
        /// </remarks>
        /// <param name="culture">The culture of the <see cref="BreakIterator"/> instance to return.</param>
        /// <returns>A word <see cref="BreakIterator"/> instance.</returns>
        public static BreakIterator GetWordInstance(CultureInfo culture)
        {
            switch (culture.TwoLetterISOLanguageName)
            {
            case "th":     // Thai
            case "lo":     // Lao
            case "my":     // Burmese
            case "km":     // Khmer
            case "ja":     // Japanese
            case "ko":     // Korean
            case "zh":     // Chinese
                return(BreakIterator.GetWordInstance(culture));
            }

            return(WordInstance);
        }
Esempio n. 3
0
        public void TestWordIteration()
        {
            BreakIterator bi = GetWordInstance(CultureInfo.InvariantCulture);

            bi.SetText(TEXT);

            int temp;

            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(0, temp);

            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(6, temp);

            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(6, temp);

            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(7, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(7, temp);
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(13, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(13, temp);
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(14, temp);
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(16, temp);
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(17, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(17, temp);

            temp = bi.Previous();
            Console.WriteLine(temp);
            assertEquals(16, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(16, temp);
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(17, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(17, temp);
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(18, temp);

            temp = bi.Last();
            Console.WriteLine(temp);
            assertEquals(107, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(107, temp);
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(-1, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(107, temp);
            temp = bi.Previous();
            Console.WriteLine(temp);
            assertEquals(106, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(106, temp);
            temp = bi.Previous();
            Console.WriteLine(temp);
            assertEquals(102, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(102, temp);
            temp = bi.Previous();
            Console.WriteLine(temp);
            assertEquals(101, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(101, temp);
        }
Esempio n. 4
0
        public void TestSentenceIteration()
        {
            BreakIterator bi = GetSentenceInstance(CultureInfo.InvariantCulture);

            bi.SetText(SENTENCE_TEXT);

            int temp;

            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(0, temp);

            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(108, temp);

            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(108, temp);

            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(221, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(221, temp);
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(290, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(290, temp);
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(324, temp);
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(344, temp);
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(364, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(364, temp);

            temp = bi.Previous();
            Console.WriteLine(temp);
            assertEquals(344, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(344, temp);
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(364, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(364, temp);
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(380, temp);

            temp = bi.First();
            Console.WriteLine(temp);
            assertEquals(0, temp);

            temp = bi.Last();
            Console.WriteLine(temp);
            assertEquals(400, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(400, temp);
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(-1, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(400, temp);
            temp = bi.Previous();
            Console.WriteLine(temp);
            assertEquals(380, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(380, temp);
            temp = bi.Previous();
            Console.WriteLine(temp);
            assertEquals(364, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(364, temp);
            temp = bi.Previous();
            Console.WriteLine(temp);
            assertEquals(344, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(344, temp);
        }
Esempio n. 5
0
        public void TestWordPreceding()
        {
            BreakIterator bi = GetWordInstance(CultureInfo.InvariantCulture);

            bi.SetText(TEXT);

            int temp;

            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(0, temp);
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(6, temp);


            temp = bi.Preceding(70);
            Console.WriteLine(temp);
            assertEquals(67, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(67, temp);
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(73, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(73, temp);
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(74, temp);
            temp = bi.Preceding(107); // Test the final boundary
            Console.WriteLine(temp);
            assertEquals(106, temp);
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(107, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(107, temp);

            temp = bi.Preceding(66); // Test exactly on a boundary position
            Console.WriteLine(temp);
            assertEquals(60, temp);
            temp = bi.Previous();
            Console.WriteLine(temp);
            assertEquals(59, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(59, temp);

            temp = bi.Preceding(0); // Test the first boundary
            Console.WriteLine(temp);
            assertEquals(-1, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(0, temp);
            temp = bi.Next();
            Console.WriteLine(temp);
            assertEquals(6, temp);
            temp = bi.Current;
            Console.WriteLine(temp);
            assertEquals(6, temp);
        }