Example #1
0
 private void checkIterator(CharsTrie.Enumerator iter, StringAndValue[] data, int dataLength)
 {
     for (int i = 0; i < dataLength; ++i)
     {
         if (!iter.MoveNext())
         {
             Errln("trie iterator hasNext()=false for item " + i + ": " + data[i].s);
             break;
         }
         CharsTrie.Entry entry          = iter.Current;
         String          expectedString = data[i].s;
         if (!expectedString.ContentEquals(entry.Chars))
         {
             Errln(String.Format("trie iterator next().getString()={0} but expected {1} for item {2}",
                                 entry.Chars, data[i].s, i));
         }
         if (entry.Value != data[i].value)
         {
             Errln(String.Format("trie iterator next().getValue()={0}=0x{1:x} but expected {2}=0x{3:x} for item {4}: {5}",
                                 entry.Value, entry.Value,
                                 data[i].value, data[i].value,
                                 i, data[i].s));
         }
     }
     if (iter.MoveNext())
     {
         Errln("trie iterator hasNext()=true after all items");
     }
     //try // ICU4N specific - not applicable in .NET
     //{
     //    iter.Next();
     //    Errln("trie iterator next() did not throw NoSuchElementException after all items");
     //}
     //catch (NoSuchElementException e)
     //{
     //    // good
     //}
 }
Example #2
0
        private bool GetCEsFromContractionCE32(CollationData data, int ce32)
        {
            int trieIndex = Collation.IndexFromCE32(ce32);

            ce32 = data.GetCE32FromContexts(trieIndex);  // Default if no suffix match.
                                                         // Since the original ce32 is not a prefix mapping,
                                                         // the default ce32 must not be another contraction.
            Debug.Assert(!Collation.IsContractionCE32(ce32));
            int contractionIndex = contractionCEs.Count;

            if (GetCEsFromCE32(data, Collation.SENTINEL_CP, ce32))
            {
                AddContractionEntry(CollationFastLatin.CONTR_CHAR_MASK, ce0, ce1);
            }
            else
            {
                // Bail out for c-without-contraction.
                AddContractionEntry(CollationFastLatin.CONTR_CHAR_MASK, Collation.NO_CE, 0);
            }
            // Handle an encodable contraction unless the next contraction is too long
            // and starts with the same character.
            int  prevX          = -1;
            bool addContraction = false;

            using (CharsTrie.Enumerator suffixes = CharsTrie.GetEnumerator(data.contexts, trieIndex + 2, 0))
            {
                while (suffixes.MoveNext())
                {
                    CharsTrie.Entry entry  = suffixes.Current;
                    ICharSequence   suffix = entry.Chars;
                    int             x      = CollationFastLatin.GetCharIndex(suffix[0]);
                    if (x < 0)
                    {
                        continue;
                    }                         // ignore anything but fast Latin text
                    if (x == prevX)
                    {
                        if (addContraction)
                        {
                            // Bail out for all contractions starting with this character.
                            AddContractionEntry(x, Collation.NO_CE, 0);
                            addContraction = false;
                        }
                        continue;
                    }
                    if (addContraction)
                    {
                        AddContractionEntry(prevX, ce0, ce1);
                    }
                    ce32 = entry.Value;
                    if (suffix.Length == 1 && GetCEsFromCE32(data, Collation.SENTINEL_CP, ce32))
                    {
                        addContraction = true;
                    }
                    else
                    {
                        AddContractionEntry(x, Collation.NO_CE, 0);
                        addContraction = false;
                    }
                    prevX = x;
                }
            }
            if (addContraction)
            {
                AddContractionEntry(prevX, ce0, ce1);
            }
            // Note: There might not be any fast Latin contractions, but
            // we need to enter contraction handling anyway so that we can bail out
            // when there is a non-fast-Latin character following.
            // For example: Danish &Y<<u+umlaut, when we compare Y vs. u\u0308 we need to see the
            // following umlaut and bail out, rather than return the difference of Y vs. u.
            ce0 = (Collation.NO_CE_PRIMARY << 32) | CONTRACTION_FLAG | contractionIndex;
            ce1 = 0;
            return(true);
        }