Exemplo n.º 1
0
        // protected constructor ----------------------------------------------

        /**
         * Protected constructor for use by subclasses.
         * Initializes the iterator with the argument target text for searching
         * and sets the BreakIterator.
         * See class documentation for more details on the use of the target text
         * and {@link BreakIterator}.
         *
         * @param target The target text to be searched.
         * @param breaker A {@link BreakIterator} that is used to determine the
         *                boundaries of a logical match. This argument can be null.
         * @exception IllegalArgumentException thrown when argument target is null,
         *            or of length 0
         * @see BreakIterator
         * @stable ICU 2.0
         */
        protected SearchIterator(CharacterIterator target, BreakIterator breaker)
        {
            this.search_ = new Search(this);

            if (target == null ||
                (target.EndIndex - target.BeginIndex) == 0)
            {
                throw new ArgumentException(
                          "Illegal argument target. " +
                          " Argument can not be null or of length 0");
            }

            search_.SetTarget(target);
            search_.BreakIterator = breaker;
            if (search_.BreakIterator != null)
            {
                search_.BreakIterator.SetText((CharacterIterator)target.Clone());
            }
            search_.isOverlap_             = false;
            search_.isCanonicalMatch_      = false;
            search_.elementComparisonType_ = SearchIteratorElementComparisonType.StandardElementComparison;
            search_.isForwardSearching_    = true;
            search_.reset_        = true;
            search_.matchedIndex_ = Done;
            search_.MatchedLength = 0;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Set the target text to be searched. Text iteration will then begin at
        /// the start of the text string. This method is useful if you want to
        /// reuse an iterator to search within a different body of text.
        /// </summary>
        /// <param name="text">New text iterator to look for match.</param>
        /// <exception cref="ArgumentException">Thrown when text is null or has 0 length.</exception>
        /// <see cref="Target"/>
        /// <stable>ICU 2.4</stable>
        public virtual void SetTarget(CharacterIterator text)
        {
            if (text == null || text.EndIndex == text.Index)
            {
                throw new ArgumentException("Illegal null or empty text");
            }

            text.SetIndex(text.BeginIndex);
            search_.SetTarget(text);
            search_.matchedIndex_       = Done;
            search_.MatchedLength       = 0;
            search_.reset_              = true;
            search_.isForwardSearching_ = true;
            if (search_.BreakIterator != null)
            {
                // Create a clone of CharacterItearator, so it won't
                // affect the position currently held by search_.text()
                search_.BreakIterator.SetText((CharacterIterator)text.Clone());
            }
            if (search_.internalBreakIter_ != null)
            {
                search_.internalBreakIter_.SetText((CharacterIterator)text.Clone());
            }
        }
Exemplo n.º 3
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");
            }
        }
Exemplo n.º 4
0
 /// <seealso cref="UCharacterIterator.GetCharacterIterator()"/>
 public override CharacterIterator GetCharacterIterator()
 {
     return((CharacterIterator)iterator.Clone());
 }