示例#1
0
        public static int Previous32(CharacterIterator ci)
        {
            if (ci.Index <= ci.BeginIndex)
            {
                return(Done32);
            }
            char trail  = ci.Previous();
            int  retVal = trail;

            if (UTF16.IsTrailSurrogate(trail) && ci.Index > ci.BeginIndex)
            {
                char lead = ci.Previous();
                if (UTF16.IsLeadSurrogate(lead))
                {
                    retVal = (((int)lead - UTF16.LeadSurrogateMinValue) << 10) +
                             ((int)trail - UTF16.TrailSurrogateMinValue) +
                             UTF16.SupplementaryMinValue;
                }
                else
                {
                    ci.Next();
                }
            }
            return(retVal);
        }
示例#2
0
        public static int Current32(CharacterIterator ci)
        {
            char lead   = ci.Current;
            int  retVal = lead;

            if (retVal < UTF16.LeadSurrogateMinValue)
            {
                return(retVal);
            }
            if (UTF16.IsLeadSurrogate(lead))
            {
                int trail = (int)ci.Next();
                ci.Previous();
                if (UTF16.IsTrailSurrogate((char)trail))
                {
                    retVal = ((lead - UTF16.LeadSurrogateMinValue) << 10) +
                             (trail - UTF16.TrailSurrogateMinValue) +
                             UTF16.SupplementaryMinValue;
                }
            }
            else
            {
                if (lead == CharacterIterator.Done)
                {
                    if (ci.Index >= ci.EndIndex)
                    {
                        retVal = Done32;
                    }
                }
            }
            return(retVal);
        }
示例#3
0
        public static int Previous32(CharacterIterator ci)
        {
            if (ci.Index <= ci.BeginIndex)
            {
                return(DONE32);
            }
            char trail  = ci.Previous();
            int  retVal = trail;

            if (UTF16.IsTrailSurrogate(trail) && ci.Index > ci.BeginIndex)
            {
                char lead = ci.Previous();
                if (UTF16.IsLeadSurrogate(lead))
                {
                    retVal = (((int)lead - UTF16.LEAD_SURROGATE_MIN_VALUE) << 10) +
                             ((int)trail - UTF16.TRAIL_SURROGATE_MIN_VALUE) +
                             UTF16.SUPPLEMENTARY_MIN_VALUE;
                }
                else
                {
                    ci.Next();
                }
            }
            return(retVal);
        }
示例#4
0
        public static int Current32(CharacterIterator ci)
        {
            char lead   = ci.Current;
            int  retVal = lead;

            if (retVal < UTF16.LEAD_SURROGATE_MIN_VALUE)
            {
                return(retVal);
            }
            if (UTF16.IsLeadSurrogate(lead))
            {
                int trail = (int)ci.Next();
                ci.Previous();
                if (UTF16.IsTrailSurrogate((char)trail))
                {
                    retVal = ((lead - UTF16.LEAD_SURROGATE_MIN_VALUE) << 10) +
                             (trail - UTF16.TRAIL_SURROGATE_MIN_VALUE) +
                             UTF16.SUPPLEMENTARY_MIN_VALUE;
                }
            }
            else
            {
                if (lead == CharacterIterator.DONE)
                {
                    if (ci.Index >= ci.EndIndex)
                    {
                        retVal = DONE32;
                    }
                }
            }
            return(retVal);
        }
示例#5
0
        /// <summary>
        /// Get the value associated with a pair of surrogates.
        /// </summary>
        /// <param name="lead">A lead surrogate.</param>
        /// <param name="trail">A trail surrogate.</param>
        public int GetSurrogateValue(char lead, char trail)
        {
            if (!UTF16.IsLeadSurrogate(lead) || !UTF16.IsTrailSurrogate(trail))
            {
                throw new ArgumentException(
                          "Argument characters do not form a supplementary character");
            }
            // get fold position for the next trail surrogate
            int offset = GetSurrogateOffset(lead, trail);

            // get the real data from the folded lead/trail units
            if (offset > 0)
            {
                return(m_data_[offset]);
            }

            // return m_initialValue_ if there is an error
            return(m_initialValue_);
        }
示例#6
0
        /// <summary>
        /// Out-of-line portion of the in-line <see cref="Next32(CharacterIterator)"/> code.
        /// The call site does an initial ci.Next() and calls this function
        /// if the 16 bit value it gets is >= <see cref="UTF16.LeadSurrogateMinValue"/>.
        /// </summary>
        // NOTE:  we leave the underlying char iterator positioned in the
        //        middle of a surrogate pair.  ci.next() will work correctly
        //        from there, but the ci.getIndex() will be wrong, and needs
        //        adjustment.
        public static int NextTrail32(CharacterIterator ci, int lead)
        {
            if (lead == CharacterIterator.Done && ci.Index >= ci.EndIndex)
            {
                return(Done32);
            }
            int retVal = lead;

            if (lead <= UTF16.LeadSurrogateMaxValue)
            {
                char cTrail = ci.Next();
                if (UTF16.IsTrailSurrogate(cTrail))
                {
                    retVal = ((lead - UTF16.LeadSurrogateMinValue) << 10) +
                             (cTrail - UTF16.TrailSurrogateMinValue) +
                             UTF16.SupplementaryMinValue;
                }
                else
                {
                    ci.Previous();
                }
            }
            return(retVal);
        }
示例#7
0
        /// <summary>
        /// Out-of-line portion of the in-line <see cref="Next32(CharacterIterator)"/> code.
        /// The call site does an initial ci.Next() and calls this function
        /// if the 16 bit value it gets is >= <see cref="UTF16.LEAD_SURROGATE_MIN_VALUE"/>.
        /// </summary>
        // NOTE:  we leave the underlying char iterator positioned in the
        //        middle of a surrogate pair.  ci.next() will work correctly
        //        from there, but the ci.getIndex() will be wrong, and needs
        //        adjustment.
        public static int NextTrail32(CharacterIterator ci, int lead)
        {
            if (lead == CharacterIterator.DONE && ci.Index >= ci.EndIndex)
            {
                return(DONE32);
            }
            int retVal = lead;

            if (lead <= UTF16.LEAD_SURROGATE_MAX_VALUE)
            {
                char cTrail = ci.Next();
                if (UTF16.IsTrailSurrogate(cTrail))
                {
                    retVal = ((lead - UTF16.LEAD_SURROGATE_MIN_VALUE) << 10) +
                             (cTrail - UTF16.TRAIL_SURROGATE_MIN_VALUE) +
                             UTF16.SUPPLEMENTARY_MIN_VALUE;
                }
                else
                {
                    ci.Previous();
                }
            }
            return(retVal);
        }
示例#8
0
        private void _testTrieIteration(Int32Trie trie, CheckRange[] checkRanges,
                                        int countCheckRanges)
        {
            // write a string
            int          countValues = 0;
            StringBuffer s           = new StringBuffer();

            int[] values = new int[30];
            for (int i = 0; i < countCheckRanges; ++i)
            {
                int c = checkRanges[i].Limit;
                if (c != 0)
                {
                    --c;
                    UTF16.Append(s, c);
                    values[countValues++] = checkRanges[i].Value;
                }
            }

            {
                int limit = s.Length;
                // try forward
                int p = 0;
                int i = 0;
                while (p < limit)
                {
                    int c = UTF16.CharAt(s, p);
                    p += UTF16.GetCharCount(c);
                    int value = trie.GetCodePointValue(c);
                    if (value != values[i])
                    {
                        Errln("wrong value from UTRIE_NEXT(U+"
                              + (c).ToHexString() + "): 0x"
                              + (value).ToHexString() + " instead of 0x"
                              + (values[i]).ToHexString());
                    }
                    // unlike the c version lead is 0 if c is non-supplementary
                    char lead  = UTF16.GetLeadSurrogate(c);
                    char trail = UTF16.GetTrailSurrogate(c);
                    if (lead == 0
                        ? trail != s[p - 1]
                        : !UTF16.IsLeadSurrogate(lead) ||
                        !UTF16.IsTrailSurrogate(trail) || lead != s[p - 2] ||
                        trail != s[p - 1])
                    {
                        Errln("wrong (lead, trail) from UTRIE_NEXT(U+"
                              + (c).ToHexString());
                        continue;
                    }
                    if (lead != 0)
                    {
                        value = trie.GetLeadValue(lead);
                        value = trie.GetTrailValue(value, trail);
                        if (value != trie.GetSurrogateValue(lead, trail) &&
                            value != values[i])
                        {
                            Errln("wrong value from getting supplementary "
                                  + "values (U+"
                                  + (c).ToHexString() + "): 0x"
                                  + (value).ToHexString() + " instead of 0x"
                                  + (values[i]).ToHexString());
                        }
                    }
                    ++i;
                }
            }
        }