예제 #1
0
        private static String getString(CharacterIterator ci)
        {
            StringBuffer buf = new StringBuffer(ci.EndIndex - ci.BeginIndex + 2);

            buf.Append("'");
            for (char c = ci.First(); c != CharacterIterator.DONE; c = ci.Next())
            {
                buf.Append(c);
            }
            buf.Append("'");
            return(buf.ToString());
        }
예제 #2
0
        /// <seealso cref="UCharacterIterator.GetText(char[])"/>
        public override int GetText(char[] fillIn, int offset)
        {
            int length       = iterator.EndIndex - iterator.BeginIndex;
            int currentIndex = iterator.Index;

            if (offset < 0 || offset + length > fillIn.Length)
            {
                throw new IndexOutOfRangeException(length.ToString());
            }

            for (char ch = iterator.First(); ch != CharacterIterator.Done; ch = iterator.Next())
            {
                fillIn[offset++] = ch;
            }
            iterator.SetIndex(currentIndex);

            return(length);
        }
예제 #3
0
        private string CharacterIteratorToString()
        {
            string fullText;

            if (text is CharArrayIterator charArrayIterator)
            {
                fullText = new string(charArrayIterator.Text, charArrayIterator.Start, charArrayIterator.Length);
            }
            else
            {
                // TODO: is there a better way to extract full text from arbitrary CharacterIterators?
                StringBuilder builder = new StringBuilder();
                for (char ch = text.First(); ch != CharacterIterator.Done; ch = text.Next())
                {
                    builder.Append(ch);
                }
                fullText = builder.ToString();
                text.SetIndex(text.BeginIndex);
            }
            return(fullText);
        }
예제 #4
0
        public void TestUCharacterIteratorWrapper()
        {
            String             source  = "asdfasdfjoiuyoiuy2341235679886765";
            UCharacterIterator it      = UCharacterIterator.GetInstance(source);
            CharacterIterator  wrap_ci = it.GetCharacterIterator();
            CharacterIterator  ci      = new StringCharacterIterator(source);

            wrap_ci.SetIndex(10);
            ci.SetIndex(10);
            String moves = "0+0+0--0-0-+++0--+++++++0--------++++0000----0-";
            int    c1, c2;
            char   m;
            int    movesIndex = 0;

            while (movesIndex < moves.Length)
            {
                m = moves[movesIndex++];
                if (m == '-')
                {
                    c1 = wrap_ci.Previous();
                    c2 = ci.Previous();
                }
                else if (m == '0')
                {
                    c1 = wrap_ci.Current;
                    c2 = ci.Current;
                }
                else
                {// m=='+'
                    c1 = wrap_ci.Next();
                    c2 = ci.Next();
                }

                // compare results
                if (c1 != c2)
                {
                    // copy the moves until the current (m) move, and terminate
                    String history = moves.Substring(0, movesIndex - 0); // ICU4N: Checked 2nd parameter
                    Errln("error: mismatch in Normalizer iteration at " + history + ": "
                          + "got c1= " + Hex(c1) + " != expected c2= " + Hex(c2));
                    break;
                }

                // compare indexes
                if (wrap_ci.Index != ci.Index)
                {
                    // copy the moves until the current (m) move, and terminate
                    String history = moves.Substring(0, movesIndex - 0); // ICU4N: Checked 2nd parameter
                    Errln("error: index mismatch in Normalizer iteration at "
                          + history + " : " + "Normalizer index " + wrap_ci.Index
                          + " expected " + ci.Index);
                    break;
                }
            }
            if (ci.First() != wrap_ci.First())
            {
                Errln("CharacterIteratorWrapper.First() failed. expected: " + ci.First() + " got: " + wrap_ci.First());
            }
            if (ci.Last() != wrap_ci.Last())
            {
                Errln("CharacterIteratorWrapper.Last() failed expected: " + ci.Last() + " got: " + wrap_ci.Last());
            }
            if (ci.BeginIndex != wrap_ci.BeginIndex)
            {
                Errln("CharacterIteratorWrapper.BeginIndex failed expected: " + ci.BeginIndex + " got: " + wrap_ci.BeginIndex);
            }
            if (ci.EndIndex != wrap_ci.EndIndex)
            {
                Errln("CharacterIteratorWrapper.EndIndex failed expected: " + ci.EndIndex + " got: " + wrap_ci.EndIndex);
            }
            try
            {
                CharacterIterator cloneWCI = (CharacterIterator)wrap_ci.Clone();
                if (wrap_ci.Index != cloneWCI.Index)
                {
                    Errln("CharacterIteratorWrapper.Clone() failed expected: " + wrap_ci.Index + " got: " + cloneWCI.Index);
                }
            }
            catch (Exception e)
            {
                Errln("CharacterIterator.Clone() failed");
            }
        }
예제 #5
0
        public void TestPreviousNext()
        {
            // src and expect strings
            char[] src =
            {
                UTF16.GetLeadSurrogate(0x2f999), UTF16.GetTrailSurrogate(0x2f999),
                UTF16.GetLeadSurrogate(0x1d15f), UTF16.GetTrailSurrogate(0x1d15f),
                (char)0xc4,
                (char)0x1ed0
            };
            // iterators
            UCharacterIterator iter1 = UCharacterIterator.GetInstance(new ReplaceableString(new String(src)));
            UCharacterIterator iter2 = UCharacterIterator.GetInstance(src /*char array*/);
            UCharacterIterator iter3 = UCharacterIterator.GetInstance(new StringCharacterIterator(new String(src)));
            UCharacterIterator iter4 = UCharacterIterator.GetInstance(new StringBuffer(new String(src)));

            previousNext(iter1);
            previousNext(iter2);
            previousNext(iter3);
            previousNext(iter4);
            getText(iter1, new String(src));
            getText(iter2, new String(src));
            getText(iter3, new String(src));
            /* getCharacterIterator */
            CharacterIterator citer1 = iter1.GetCharacterIterator();
            CharacterIterator citer2 = iter2.GetCharacterIterator();
            CharacterIterator citer3 = iter3.GetCharacterIterator();

            if (citer1.First() != iter1.Current)
            {
                Errln("getCharacterIterator for iter1 failed");
            }
            if (citer2.First() != iter2.Current)
            {
                Errln("getCharacterIterator for iter2 failed");
            }
            if (citer3.First() != iter3.Current)
            {
                Errln("getCharacterIterator for iter3 failed");
            }
            /* Test clone()  && moveIndex()*/
            try
            {
                UCharacterIterator clone1 = (UCharacterIterator)iter1.Clone();
                UCharacterIterator clone2 = (UCharacterIterator)iter2.Clone();
                UCharacterIterator clone3 = (UCharacterIterator)iter3.Clone();
                if (clone1.MoveIndex(3) != iter1.MoveIndex(3))
                {
                    Errln("moveIndex for iter1 failed");
                }
                if (clone2.MoveIndex(3) != iter2.MoveIndex(3))
                {
                    Errln("moveIndex for iter2 failed");
                }
                if (clone3.MoveIndex(3) != iter3.MoveIndex(3))
                {
                    Errln("moveIndex for iter1 failed");
                }
            }
            catch (Exception e)
            {
                Errln("could not clone the iterator");
            }
        }