Ejemplo n.º 1
0
        /// <summary>
        /// Extend the FCD text segment backward or normalize around pos.
        /// To be called when checkDir &lt; 0 &amp;&amp; pos != start.
        /// Returns with checkDir == 0 and pos != start.
        /// </summary>
        private void PreviousSegment()
        {
            Debug.Assert(checkDir < 0 && seq == rawSeq && pos != start);
            // The input text [pos..segmentLimit[ passes the FCD check.
            int p      = pos;
            int nextCC = 0;

            for (; ;)
            {
                // Fetch the previous character's fcd16 value.
                int q = p;
                int c = Character.CodePointBefore(seq, p);
                p -= Character.CharCount(c);
                int fcd16   = nfcImpl.GetFCD16(c);
                int trailCC = fcd16 & 0xff;
                if (trailCC == 0 && q != pos)
                {
                    // FCD boundary after the [p, q[ character.
                    start = segmentStart = q;
                    break;
                }
                if (trailCC != 0 && ((nextCC != 0 && trailCC > nextCC) ||
                                     CollationFCD.IsFCD16OfTibetanCompositeVowel(fcd16)))
                {
                    // Fails FCD check. Find the previous FCD boundary and normalize.
                    do
                    {
                        q = p;
                        if (fcd16 <= 0xff || p == rawStart)
                        {
                            break;
                        }
                        c  = Character.CodePointBefore(seq, p);
                        p -= Character.CharCount(c);
                    } while ((fcd16 = nfcImpl.GetFCD16(c)) != 0);
                    Normalize(q, pos);
                    pos = limit;
                    break;
                }
                nextCC = fcd16 >> 8;
                if (p == rawStart || nextCC == 0)
                {
                    // FCD boundary before the following character.
                    start = segmentStart = p;
                    break;
                }
            }
            Debug.Assert(pos != start);
            checkDir = 0;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Extend the FCD text segment forward or normalize around pos.
        /// To be called when checkDir > 0 &amp;&amp; pos != limit.
        /// Returns with checkDir == 0 and pos != limit.
        /// </summary>
        private void NextSegment()
        {
            Debug.Assert(checkDir > 0 && seq == rawSeq && pos != limit);
            // The input text [segmentStart..pos[ passes the FCD check.
            int p      = pos;
            int prevCC = 0;

            for (; ;)
            {
                // Fetch the next character's fcd16 value.
                int q = p;
                int c = Character.CodePointAt(seq, p);
                p += Character.CharCount(c);
                int fcd16  = nfcImpl.GetFCD16(c);
                int leadCC = fcd16 >> 8;
                if (leadCC == 0 && q != pos)
                {
                    // FCD boundary before the [q, p[ character.
                    limit = segmentLimit = q;
                    break;
                }
                if (leadCC != 0 && (prevCC > leadCC || CollationFCD.IsFCD16OfTibetanCompositeVowel(fcd16)))
                {
                    // Fails FCD check. Find the next FCD boundary and normalize.
                    do
                    {
                        q = p;
                        if (p == rawLimit)
                        {
                            break;
                        }
                        c  = Character.CodePointAt(seq, p);
                        p += Character.CharCount(c);
                    } while (nfcImpl.GetFCD16(c) > 0xff);
                    Normalize(pos, q);
                    pos = start;
                    break;
                }
                prevCC = fcd16 & 0xff;
                if (p == rawLimit || prevCC == 0)
                {
                    // FCD boundary after the last character.
                    limit = segmentLimit = p;
                    break;
                }
            }
            Debug.Assert(pos != limit);
            checkDir = 0;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Extends the FCD text segment backward or normalizes around pos.
        /// </summary>
        /// <returns><c>true</c> if success.</returns>
        private bool PreviousSegment()
        {
            Debug.Assert(state == State.IterCheckBwd);
            // The input text [(iter index)..limit[ passes the FCD check.
            pos = iter.Index;
            // Collect the characters being checked, in case they need to be normalized.
            if (s == null)
            {
                s = new StringBuilder();
            }
            else
            {
                s.Length = 0;
            }
            int nextCC = 0;

            for (; ;)
            {
                // Fetch the previous character and its fcd16 value.
                int c = iter.PreviousCodePoint();
                if (c < 0)
                {
                    break;
                }
                int fcd16   = nfcImpl.GetFCD16(c);
                int trailCC = fcd16 & 0xff;
                if (trailCC == 0 && s.Length != 0)
                {
                    // FCD boundary after this character.
                    iter.NextCodePoint();
                    break;
                }
                s.AppendCodePoint(c);
                if (trailCC != 0 && ((nextCC != 0 && trailCC > nextCC) ||
                                     CollationFCD.IsFCD16OfTibetanCompositeVowel(fcd16)))
                {
                    // Fails FCD check. Find the previous FCD boundary and normalize.
                    while (fcd16 > 0xff)
                    {
                        c = iter.PreviousCodePoint();
                        if (c < 0)
                        {
                            break;
                        }
                        fcd16 = nfcImpl.GetFCD16(c);
                        if (fcd16 == 0)
                        {
                            iter.NextCodePoint();
                            break;
                        }
                        s.AppendCodePoint(c);
                    }
                    s.Reverse();
                    Normalize(s);
                    limit = pos;
                    start = pos - s.Length;
                    state = State.InNormIterAtStart;
                    pos   = normalized.Length;
                    return(true);
                }
                nextCC = fcd16 >> 8;
                if (nextCC == 0)
                {
                    // FCD boundary before the following character.
                    break;
                }
            }
            start = pos - s.Length;
            Debug.Assert(pos != start);
            iter.MoveIndex(s.Length);
            state = State.IterInFCDSegment;
            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Extends the FCD text segment forward or normalizes around pos.
        /// </summary>
        /// <returns><c>true</c> if success.</returns>
        private bool NextSegment()
        {
            Debug.Assert(state == State.IterCheckFwd);
            // The input text [start..(iter index)[ passes the FCD check.
            pos = iter.Index;
            // Collect the characters being checked, in case they need to be normalized.
            if (s == null)
            {
                s = new StringBuilder();
            }
            else
            {
                s.Length = 0;
            }
            int prevCC = 0;

            for (; ;)
            {
                // Fetch the next character and its fcd16 value.
                int c = iter.NextCodePoint();
                if (c < 0)
                {
                    break;
                }
                int fcd16  = nfcImpl.GetFCD16(c);
                int leadCC = fcd16 >> 8;
                if (leadCC == 0 && s.Length != 0)
                {
                    // FCD boundary before this character.
                    iter.PreviousCodePoint();
                    break;
                }
                s.AppendCodePoint(c);
                if (leadCC != 0 && (prevCC > leadCC || CollationFCD.IsFCD16OfTibetanCompositeVowel(fcd16)))
                {
                    // Fails FCD check. Find the next FCD boundary and normalize.
                    for (; ;)
                    {
                        c = iter.NextCodePoint();
                        if (c < 0)
                        {
                            break;
                        }
                        if (nfcImpl.GetFCD16(c) <= 0xff)
                        {
                            iter.PreviousCodePoint();
                            break;
                        }
                        s.AppendCodePoint(c);
                    }
                    Normalize(s);
                    start = pos;
                    limit = pos + s.Length;
                    state = State.InNormIterAtLimit;
                    pos   = 0;
                    return(true);
                }
                prevCC = fcd16 & 0xff;
                if (prevCC == 0)
                {
                    // FCD boundary after the last character.
                    break;
                }
            }
            limit = pos + s.Length;
            Debug.Assert(pos != limit);
            iter.MoveIndex(-s.Length);
            state = State.IterInFCDSegment;
            return(true);
        }