コード例 #1
0
        /// <summary>
        /// Retreat to the start of the previous code point in the text, and return it (pre-decrement semantics). If the
        /// index is not preceeded by a valid surrogate pair, the behavior is the same as <see cref="Previous()"/>. Otherwise
        /// the iterator is decremented to the start of the surrogate pair, and the code point represented by the pair is
        /// returned.
        /// </summary>
        /// <returns>The previous code point in the text, or <see cref="UForwardCharacterIterator.Done"/> if the new index is before the start of the text.</returns>
        /// <stable>ICU 2.4</stable>
        public virtual int PreviousCodePoint()
        {
            int ch1 = Previous();

            if (UTF16.IsTrailSurrogate((char)ch1))
            {
                int ch2 = Previous();
                if (UTF16.IsLeadSurrogate((char)ch2))
                {
                    return(Character.ToCodePoint((char)ch2, (char)ch1));
                }
                else if (ch2 != Done)
                {
                    // unmatched trail surrogate so back out
                    Next();
                }
            }
            return(ch1);
        }