/// <summary> /// Sets the position to <see cref="EndIndex"/>-1 (<see cref="EndIndex"/> if the text is empty) /// and returns the character at that position. /// </summary> /// <returns>The last character in the text, or <see cref="UCharacterIterator.Done"/> if the text is empty.</returns> /// <seealso cref="EndIndex"/> public override char Last() { iterator.SetToLimit(); return((char)iterator.Previous()); }
public void TestIteration() { UCharacterIterator iterator = UCharacterIterator.GetInstance( ITERATION_STRING_); UCharacterIterator iterator2 = UCharacterIterator.GetInstance( ITERATION_STRING_); iterator.SetToStart(); if (iterator.Current != ITERATION_STRING_[0]) { Errln("Iterator failed retrieving first character"); } iterator.SetToLimit(); if (iterator.Previous() != ITERATION_STRING_[ ITERATION_STRING_.Length - 1]) { Errln("Iterator failed retrieving last character"); } if (iterator.Length != ITERATION_STRING_.Length) { Errln("Iterator failed determining begin and end index"); } iterator2.Index = 0; iterator.Index = 0; int ch = 0; while (ch != UCharacterIterator.DONE) { int index = iterator2.Index; ch = iterator2.NextCodePoint(); if (index != ITERATION_SUPPLEMENTARY_INDEX) { if (ch != iterator.Next() && ch != UCharacterIterator.DONE) { Errln("Error mismatch in next() and nextCodePoint()"); } } else { if (UTF16.GetLeadSurrogate(ch) != iterator.Next() || UTF16.GetTrailSurrogate(ch) != iterator.Next()) { Errln("Error mismatch in next and nextCodePoint for " + "supplementary characters"); } } } iterator.Index = ITERATION_STRING_.Length; iterator2.Index = ITERATION_STRING_.Length; while (ch != UCharacterIterator.DONE) { int index = iterator2.Index; ch = iterator2.PreviousCodePoint(); if (index != ITERATION_SUPPLEMENTARY_INDEX) { if (ch != iterator.Previous() && ch != UCharacterIterator.DONE) { Errln("Error mismatch in previous() and " + "previousCodePoint()"); } } else { if (UTF16.GetLeadSurrogate(ch) != iterator.Previous() || UTF16.GetTrailSurrogate(ch) != iterator.Previous()) { Errln("Error mismatch in previous and " + "previousCodePoint for supplementary characters"); } } } }
/// <summary> /// Sets the position to getEndIndex()-1 (getEndIndex() if the text is empty) /// and returns the character at that position. /// </summary> /// /// <returns>the last character in the text, or DONE if the text is empty</returns> /// <seealso cref="M:IBM.ICU.Impl.UCharacterIteratorWrapper.GetEndIndex"/> public virtual char Last() { iterator.SetToLimit(); return((char)iterator.Previous()); }