Esempio n. 1
0
        public void TestIsBoundary()
        {
            bool b = bi.IsBoundary(0);

            TestFmwk.assertTrue("BreakIterator is boundary not correct", b);

            b = bi.IsBoundary(5);
            TestFmwk.assertTrue("BreakIterator is boundary not correct", b);
        }
        /// <summary>
        /// Implements the "Final_Cased" condition
        ///
        /// Specification: Within the closest word boundaries containing C, there is a cased
        /// letter before C, and there is no cased letter after C.
        ///
        /// Regular Expression:
        ///   Before C: [{cased==true}][{wordBoundary!=true}]*
        ///   After C: !([{wordBoundary!=true}]*[{cased}])
        /// </summary>
        private static bool IsFinalCased(String src, int index, Locale locale)
        {
            BreakIterator wordBoundary = BreakIterator.GetWordInstance(locale);

            wordBoundary.SetText(src);
            int ch;

            // Look for a preceding 'cased' letter
            for (int i = index; (i >= 0) && !wordBoundary.IsBoundary(i); i -= Character.CharCount(ch))
            {
                ch = src.CodePointBefore(i);
                if (IsCased(ch))
                {
                    int len = src.Length();
                    // Check that there is no 'cased' letter after the index
                    for (i = index + Character.CharCount(src.CodePointAt(index)); (i < len) && !wordBoundary.IsBoundary(i); i += Character.CharCount(ch))
                    {
                        ch = src.CodePointAt(i);
                        if (IsCased(ch))
                        {
                            return(false);
                        }
                    }

                    return(true);
                }
            }

            return(false);
        }
Esempio n. 3
0
        //---------------------------------------------
        //Internal subroutines
        //---------------------------------------------

        /* Internal subroutine used by TestIsBoundary() */
        private void doBoundaryTest(BreakIterator bi, String text, int[] boundaries)
        {
            Logln("testIsBoundary():");
            int  p = 0;
            bool isB;

            for (int i = 0; i < text.Length; i++)
            {
                isB = bi.IsBoundary(i);
                Logln("bi.isBoundary(" + i + ") -> " + isB);
                if (i == boundaries[p])
                {
                    if (!isB)
                    {
                        Errln("Wrong result from isBoundary() for " + i + ": expected true, got false");
                    }
                    p++;
                }
                else
                {
                    if (isB)
                    {
                        Errln("Wrong result from isBoundary() for " + i + ": expected false, got true");
                    }
                }
            }
        }
Esempio n. 4
0
        public void TestBug4153072()
        {
            BreakIterator iter  = BreakIterator.GetWordInstance();
            String        str   = "...Hello, World!...";
            int           begin = 3;
            int           end   = str.Length - 3;

            // not used boolean gotException = false;


            iter.SetText(new StringCharacterIterator(str, begin, end, begin));
            for (int index = -1; index < begin + 1; ++index)
            {
                try
                {
                    iter.IsBoundary(index);
                    if (index < begin)
                    {
                        Errln("Didn't get exception with offset = " + index +
                              " and begin index = " + begin);
                    }
                }
                catch (ArgumentException e)
                {
                    if (index >= begin)
                    {
                        Errln("Got exception with offset = " + index +
                              " and begin index = " + begin);
                    }
                }
            }
        }
Esempio n. 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;
        }
Esempio n. 6
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");
            }
        }
Esempio n. 7
0
        public override bool IsBoundary(int offset)
        {
            if ([email protected](offset))
            {
                return(false); // No underlying break to suppress?
            }

            // delegate thinks there's a break…
            if (backwardsTrie == null)
            {
                return(true); // no data
            }

            ResetState();
            return(!BreakExceptionAt(offset)); // if there's an exception: no break.
        }
        public void IsBoundary(BreakIterator.UBreakIteratorType type,
                               string text,
                               int[] offsetsToTest,
                               bool[] expectedIsBoundary,
                               int[] expectedOffsets) // expected BreakIterator.Current after calling IsBoundary.
        {
            var locale = new Locale("zh");

            BreakIterator bi = default(BreakIterator);

            try
            {
                switch (type)
                {
                case BreakIterator.UBreakIteratorType.SENTENCE:
                    bi = BreakIterator.CreateSentenceInstance(locale);
                    break;

                case BreakIterator.UBreakIteratorType.WORD:
                    bi = BreakIterator.CreateWordInstance(locale);
                    break;

                default:
                    throw new NotSupportedException("This iterator type is not supported in this test yet. [" + type + "]");
                }

                bi.SetText(text);

                for (int i = 0; i < offsetsToTest.Length; i++)
                {
                    var isBoundary = bi.IsBoundary(offsetsToTest[i]);

                    Assert.AreEqual(expectedIsBoundary[i], isBoundary, "Expected IsBoundary was not equal at i: {0}, offset: {1}", i, offsetsToTest[i]);
                    Assert.AreEqual(expectedOffsets[i], bi.Current);
                }
            }
            finally
            {
                if (bi != default(BreakIterator))
                {
                    bi.Dispose();
                }
            }
        }
Esempio n. 9
0
 static ThaiTokenizer()
 {
     // check that we have a working dictionary-based break iterator for thai
     proto.SetText("ภาษาไทย");
     DBBI_AVAILABLE = proto.IsBoundary(4);
 }