예제 #1
0
        protected override void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
        {
            try
            {
                this.contextMenuStrip1.Items.Clear();
                if (this.toolStripButtonSpellCheck.Checked)
                {
                    int           offset   = this.textBox1.GetCharIndexFromPosition(pointClicked);
                    BreakIterator boundary = BreakIterator.GetWordInstance();
                    boundary.Text = this.textBox1.Text;
                    end           = boundary.Following(offset);

                    if (end != BreakIterator.DONE)
                    {
                        start   = boundary.Previous();
                        curWord = this.textBox1.Text.Substring(start, end - start);
                        makeSuggestions(curWord);
                    }
                }
            }
            finally
            {
                // load standard menu items
                this.contextMenuStrip1.RepopulateContextMenu();
            }
        }
        private void Do3SentenceTest(BreakIterator bi) // LUCENENET NOTE: Refactored a bit because Substring in .NET requires some light math to match Java
        {
            assertEquals(0, bi.Current);
            assertEquals(0, bi.First());
            int current = bi.Current;

            assertEquals(SENTENCES[0], TEXT.Substring(current, bi.Next() - current)); // LUCNENENET: Corrected 2nd parameter
            current = bi.Current;
            assertEquals(SENTENCES[1], TEXT.Substring(current, bi.Next() - current)); // LUCNENENET: Corrected 2nd parameter
            current = bi.Current;
            assertEquals(bi.Text.EndIndex, bi.Next());
            int next = bi.Current;

            assertEquals(SENTENCES[2], TEXT.Substring(current, next - current)); // LUCNENENET: Corrected 2nd parameter
            assertEquals(BreakIterator.Done, bi.Next());

            assertEquals(TEXT.Length, bi.Last());
            int end  = bi.Current;
            int prev = bi.Previous();

            assertEquals(SENTENCES[2], TEXT.Substring(prev, end - prev)); // LUCNENENET: Corrected 2nd parameter
            end  = bi.Current;
            prev = bi.Previous();
            assertEquals(SENTENCES[1], TEXT.Substring(prev, end - prev)); // LUCNENENET: Corrected 2nd parameter
            end  = bi.Current;
            prev = bi.Previous();
            assertEquals(SENTENCES[0], TEXT.Substring(prev, end - prev)); // LUCNENENET: Corrected 2nd parameter
            assertEquals(BreakIterator.Done, bi.Previous());
            assertEquals(0, bi.Current);

            assertEquals(59, bi.Following(39));
            assertEquals(59, bi.Following(31));
            assertEquals(31, bi.Following(30));

            assertEquals(0, bi.Preceding(57));
            assertEquals(0, bi.Preceding(58));
            assertEquals(31, bi.Preceding(59));

            assertEquals(0, bi.First());
            assertEquals(59, bi.Next(2));
            assertEquals(0, bi.Next(-2));
        }
 private void Test0Sentences(BreakIterator bi)
 {
     assertEquals(0, bi.Current);
     assertEquals(0, bi.First());
     assertEquals(BreakIterator.Done, bi.Next());
     assertEquals(0, bi.Last());
     assertEquals(BreakIterator.Done, bi.Previous());
     assertEquals(BreakIterator.Done, bi.Following(0));
     assertEquals(BreakIterator.Done, bi.Preceding(0));
     assertEquals(0, bi.First());
     assertEquals(BreakIterator.Done, bi.Next(13));
     assertEquals(BreakIterator.Done, bi.Next(-8));
 }
예제 #4
0
        /** Asserts that two breakiterators break the text the same way */
        public void assertSameBreaks(CharacterIterator one, CharacterIterator two, BreakIterator expected, BreakIterator actual)
        {
            expected.SetText(one);
            actual.SetText(two);

            assertEquals(expected.Current, actual.Current);

            // next()
            int v = expected.Current;

            while (v != BreakIterator.DONE)
            {
                assertEquals(v = expected.Next(), actual.Next());
                assertEquals(expected.Current, actual.Current);
            }

            // first()
            assertEquals(expected.First(), actual.First());
            assertEquals(expected.Current, actual.Current);
            // last()
            assertEquals(expected.Last(), actual.Last());
            assertEquals(expected.Current, actual.Current);

            // previous()
            v = expected.Current;
            while (v != BreakIterator.DONE)
            {
                assertEquals(v = expected.Previous(), actual.Previous());
                assertEquals(expected.Current, actual.Current);
            }

            // following()
            for (int i = one.BeginIndex; i <= one.EndIndex; i++)
            {
                expected.First();
                actual.First();
                assertEquals(expected.Following(i), actual.Following(i));
                assertEquals(expected.Current, actual.Current);
            }

            // preceding()
            for (int i = one.BeginIndex; i <= one.EndIndex; i++)
            {
                expected.Last();
                actual.Last();
                assertEquals(expected.Preceding(i), actual.Preceding(i));
                assertEquals(expected.Current, actual.Current);
            }
        }
예제 #5
0
        private void MakeLayoutWindow(int localStart)
        {
            int compStart = localStart;
            int compLimit = FChars.Length;

            // If we've already gone past the layout window, format to end of paragraph
            if (LayoutCount > 0 && !HaveLayoutWindow)
            {
                float avgLineLength = System.Math.Max(LayoutCharCount / LayoutCount, 1);
                compLimit = System.Math.Min(localStart + (int)(avgLineLength * EST_LINES), FChars.Length);
            }

            if (localStart > 0 || compLimit < FChars.Length)
            {
                if (CharIter == null)
                {
                    CharIter = new CharArrayIterator(FChars);
                }
                else
                {
                    CharIter.Reset(FChars);
                }
                if (FLineBreak == null)
                {
                    FLineBreak = BreakIterator.LineInstance;
                }
                FLineBreak.SetText(CharIter);
                if (localStart > 0)
                {
                    if (!FLineBreak.IsBoundary(localStart))
                    {
                        compStart = FLineBreak.Preceding(localStart);
                    }
                }
                if (compLimit < FChars.Length)
                {
                    if (!FLineBreak.IsBoundary(compLimit))
                    {
                        compLimit = FLineBreak.Following(compLimit);
                    }
                }
            }

            EnsureComponents(compStart, compLimit);
            HaveLayoutWindow = true;
        }
예제 #6
0
        private void _testFollowing(BreakIterator bi, String text, int[] boundaries)
        {
            Logln("testFollowing():");
            int p = 2;

            for (int i = 0; i <= text.Length; i++)
            {
                if (i == boundaries[p])
                {
                    ++p;
                }

                int b = bi.Following(i);
                Logln("bi.following(" + i + ") -> " + b);
                if (b != boundaries[p])
                {
                    Errln("Wrong result from following() for " + i + ": expected " + boundaries[p]
                          + ", got " + b);
                }
            }
        }
예제 #7
0
        public void TestPreceding()
        {
            String        words3 = "aaa bbb ccc";
            BreakIterator e      = BreakIterator.GetWordInstance(CultureInfo.CurrentCulture);

            e.SetText(words3);
            e.First();
            int p1 = e.Next();
            int p2 = e.Next();
            int p3 = e.Next();
            int p4 = e.Next();

            int f = e.Following(p2 + 1);
            int p = e.Preceding(p2 + 1);

            if (f != p3)
            {
                Errln("IntlTestTextBoundary::TestPreceding: f!=p3");
            }
            if (p != p2)
            {
                Errln("IntlTestTextBoundary::TestPreceding: p!=p2");
            }

            if (p1 + 1 != p2)
            {
                Errln("IntlTestTextBoundary::TestPreceding: p1+1!=p2");
            }

            if (p3 + 1 != p4)
            {
                Errln("IntlTestTextBoundary::TestPreceding: p3+1!=p4");
            }

            if (!e.IsBoundary(p2) || e.IsBoundary(p2 + 1) || !e.IsBoundary(p3))
            {
                Errln("IntlTestTextBoundary::TestPreceding: isBoundary err");
            }
        }
예제 #8
0
        public void TestThaiDictionaryBreakIterator()
        {
            int position;
            int index;

            int[]  result = { 1, 2, 5, 10, 11, 12, 11, 10, 5, 2, 1, 0 };
            char[] ctext  =
            {
                (char)0x0041, (char)0x0020,
                (char)0x0E01, (char)0x0E32,(char)0x0E23,  (char)0x0E17, (char)0x0E14, (char)0x0E25, (char)0x0E2D, (char)0x0E07,
                (char)0x0020, (char)0x0041
            };
            String text = new String(ctext);

            ULocale       locale = ULocale.CreateCanonical("th");
            BreakIterator b      = BreakIterator.GetWordInstance(locale);

            b.SetText(text);

            index = 0;
            // Test forward iteration
            while ((position = b.Next()) != BreakIterator.Done)
            {
                if (position != result[index++])
                {
                    Errln("Error with ThaiDictionaryBreakIterator forward iteration test at " + position + ".\nShould have been " + result[index - 1]);
                }
            }

            // Test backward iteration
            while ((position = b.Previous()) != BreakIterator.Done)
            {
                if (position != result[index++])
                {
                    Errln("Error with ThaiDictionaryBreakIterator backward iteration test at " + position + ".\nShould have been " + result[index - 1]);
                }
            }

            //Test invalid sequence and spaces
            char[] text2 =
            {
                (char)0x0E01, (char)0x0E39, (char)0x0020, (char)0x0E01, (char)0x0E34, (char)0x0E19, (char)0x0E01, (char)0x0E38, (char)0x0E49, (char)0x0E07, (char)0x0020, (char)0x0E1B,
                (char)0x0E34, (char)0x0E49, (char)0x0E48, (char)0x0E07, (char)0x0E2D, (char)0x0E22, (char)0x0E39, (char)0x0E48, (char)0x0E43, (char)0x0E19,
                (char)0x0E16, (char)0x0E49, (char)0x0E33
            };
            int[] expectedWordResult =
            {
                2, 3, 6, 10, 11, 15, 17, 20, 22
            };
            int[] expectedLineResult =
            {
                3, 6, 11, 15, 17, 20, 22
            };
            BreakIterator brk = BreakIterator.GetWordInstance(new ULocale("th"));

            brk.SetText(new String(text2));
            position = index = 0;
            while ((position = brk.Next()) != BreakIterator.Done && position < text2.Length)
            {
                if (position != expectedWordResult[index++])
                {
                    Errln("Incorrect break given by thai word break iterator. Expected: " + expectedWordResult[index - 1] + " Got: " + position);
                }
            }

            brk = BreakIterator.GetLineInstance(new ULocale("th"));
            brk.SetText(new String(text2));
            position = index = 0;
            while ((position = brk.Next()) != BreakIterator.Done && position < text2.Length)
            {
                if (position != expectedLineResult[index++])
                {
                    Errln("Incorrect break given by thai line break iterator. Expected: " + expectedLineResult[index - 1] + " Got: " + position);
                }
            }
            // Improve code coverage
            if (brk.Preceding(expectedLineResult[1]) != expectedLineResult[0])
            {
                Errln("Incorrect preceding position.");
            }
            if (brk.Following(expectedLineResult[1]) != expectedLineResult[2])
            {
                Errln("Incorrect following position.");
            }
            int[] fillInArray = new int[2];
            if (((RuleBasedBreakIterator)brk).GetRuleStatusVec(fillInArray) != 1 || fillInArray[0] != 0)
            {
                Errln("Error: Since getRuleStatusVec is not supported in DictionaryBasedBreakIterator, it should return 1 and fillInArray[0] == 0.");
            }
        }
예제 #9
0
 public override int Following(int offset)
 {
     return(InternalNext(@delegate.Following(offset)));
 }
예제 #10
0
        /// <summary>
        /// Returns the position at the end of the next layout.  Does NOT
        /// update the current position of this <code>LineBreakMeasurer</code>.
        /// </summary>
        /// <param name="wrappingWidth"> the maximum visible advance permitted for
        ///    the text in the next layout </param>
        /// <param name="offsetLimit"> the first character that can not be included
        ///    in the next layout, even if the text after the limit would fit
        ///    within the wrapping width; <code>offsetLimit</code> must be
        ///    greater than the current position </param>
        /// <param name="requireNextWord"> if <code>true</code>, the current position
        ///    that is returned if the entire next word does not fit within
        ///    <code>wrappingWidth</code>; if <code>false</code>, the offset
        ///    returned is at least one greater than the current position </param>
        /// <returns> an offset in the text representing the limit of the
        ///    next <code>TextLayout</code> </returns>
        public int NextOffset(float wrappingWidth, int offsetLimit, bool requireNextWord)
        {
            int nextOffset = Pos;

            if (Pos < Limit)
            {
                if (offsetLimit <= Pos)
                {
                    throw new IllegalArgumentException("offsetLimit must be after current position");
                }

                int charAtMaxAdvance = Measurer.GetLineBreakIndex(Pos, wrappingWidth);

                if (charAtMaxAdvance == Limit)
                {
                    nextOffset = Limit;
                }
                else if (char.IsWhiteSpace(Measurer.Chars[charAtMaxAdvance - Start]))
                {
                    nextOffset = BreakIter.Following(charAtMaxAdvance);
                }
                else
                {
                    // Break is in a word;  back up to previous break.

                    // NOTE:  I think that breakIter.preceding(limit) should be
                    // equivalent to breakIter.last(), breakIter.previous() but
                    // the authors of BreakIterator thought otherwise...
                    // If they were equivalent then the first branch would be
                    // unnecessary.
                    int testPos = charAtMaxAdvance + 1;
                    if (testPos == Limit)
                    {
                        BreakIter.Last();
                        nextOffset = BreakIter.Previous();
                    }
                    else
                    {
                        nextOffset = BreakIter.Preceding(testPos);
                    }

                    if (nextOffset <= Pos)
                    {
                        // first word doesn't fit on line
                        if (requireNextWord)
                        {
                            nextOffset = Pos;
                        }
                        else
                        {
                            nextOffset = System.Math.Max(Pos + 1, charAtMaxAdvance);
                        }
                    }
                }
            }

            if (nextOffset > offsetLimit)
            {
                nextOffset = offsetLimit;
            }

            return(nextOffset);
        }