コード例 #1
0
 private void AddPrefixes(CollationData d, int c, string p, int pidx) // ICU4N specific - changed p from ICharSequence to string
 {
     using (CharsTrieEnumerator prefixes = new CharsTrie(p, pidx).GetEnumerator())
     {
         while (prefixes.MoveNext())
         {
             var e = prefixes.Current;
             AddPrefix(d, e.Chars, c, e.Value);
         }
     }
 }
コード例 #2
0
ファイル: CharsTrieTest.cs プロジェクト: NightOwl888/ICU4N
        public void Test41GetNextChars()
        {
            CharsTrie     trie   = buildMonthsTrie(TrieBuilderOption.Small);
            StringBuilder buffer = new StringBuilder();
            int           count  = trie.GetNextChars(buffer);

            if (count != 2 || !"aj".ContentEquals(buffer))
            {
                Errln("months getNextChars()!=[aj] at root");
            }
            trie.Next('j');
            trie.Next('a');
            trie.Next('n');
            // getNextChars() directly after next()
            buffer.Length = (0);
            count         = trie.GetNextChars(buffer);
            if (count != 20 || !".abcdefghijklmnopqru".ContentEquals(buffer))
            {
                Errln("months getNextChars()!=[.abcdefghijklmnopqru] after \"jan\"");
            }
            // getNextChars() after getValue()
            trie.GetValue();  // next() had returned BytesTrie.Result.INTERMEDIATE_VALUE.
            buffer.Length = (0);
            count         = trie.GetNextChars(buffer);
            if (count != 20 || !".abcdefghijklmnopqru".ContentEquals(buffer))
            {
                Errln("months getNextChars()!=[.abcdefghijklmnopqru] after \"jan\"+getValue()");
            }
            // getNextChars() from a linear-match node
            trie.Next('u');
            buffer.Length = (0);
            count         = trie.GetNextChars(buffer);
            if (count != 1 || !"a".ContentEquals(buffer))
            {
                Errln("months getNextChars()!=[a] after \"janu\"");
            }
            trie.Next('a');
            buffer.Length = (0);
            count         = trie.GetNextChars(buffer);
            if (count != 1 || !"r".ContentEquals(buffer))
            {
                Errln("months getNextChars()!=[r] after \"janua\"");
            }
            trie.Next('r');
            trie.Next('y');
            // getNextChars() after a final match
            buffer.Length = (0);
            count         = trie.GetNextChars(buffer);
            if (count != 0 || buffer.Length != 0)
            {
                Errln("months getNextChars()!=[] after \"january\"");
            }
        }
コード例 #3
0
ファイル: CharsTrieTest.cs プロジェクト: NightOwl888/ICU4N
        public void Test32NextForCodePoint()
        {
            StringAndValue[] data =
            {
                // "\u4dff\\U00010000\u9999\\U00020000\udfff\\U0010ffff"
                new StringAndValue("\u4dff\ud800\udc00\u9999\ud840\udc00\udfff\udbff\udfff", 2000000000),
                // "\u4dff\\U00010000\u9999\\U00020002"
                new StringAndValue("\u4dff\ud800\udc00\u9999\ud840\udc02",                        44444),
                // "\u4dff\\U000103ff"
                new StringAndValue("\u4dff\ud800\udfff", 99999)
            };
            CharsTrie trie = buildTrie(data, data.Length, TrieBuilderOption.Fast);
            Result    result;

            if ((result = trie.NextForCodePoint(0x4dff)) != Result.NoValue || result != trie.Current ||
                (result = trie.NextForCodePoint(0x10000)) != Result.NoValue || result != trie.Current ||
                (result = trie.NextForCodePoint(0x9999)) != Result.NoValue || result != trie.Current ||
                (result = trie.NextForCodePoint(0x20000)) != Result.NoValue || result != trie.Current ||
                (result = trie.NextForCodePoint(0xdfff)) != Result.NoValue || result != trie.Current ||
                (result = trie.NextForCodePoint(0x10ffff)) != Result.FinalValue || result != trie.Current ||
                trie.GetValue() != 2000000000
                )
            {
                Errln("CharsTrie.NextForCodePoint() fails for " + data[0].s);
            }
            if ((result = trie.FirstForCodePoint(0x4dff)) != Result.NoValue || result != trie.Current ||
                (result = trie.NextForCodePoint(0x10000)) != Result.NoValue || result != trie.Current ||
                (result = trie.NextForCodePoint(0x9999)) != Result.NoValue || result != trie.Current ||
                (result = trie.NextForCodePoint(0x20002)) != Result.FinalValue || result != trie.Current ||
                trie.GetValue() != 44444
                )
            {
                Errln("CharsTrie.NextForCodePoint() fails for " + data[1].s);
            }
            if ((result = trie.Reset().NextForCodePoint(0x4dff)) != Result.NoValue || result != trie.Current ||
                (result = trie.NextForCodePoint(0x10000)) != Result.NoValue || result != trie.Current ||
                (result = trie.NextForCodePoint(0x9999)) != Result.NoValue || result != trie.Current ||
                (result = trie.NextForCodePoint(0x20222)) != Result.NoMatch || result != trie.Current  // no match for trail surrogate
                )
            {
                Errln("CharsTrie.NextForCodePoint() fails for \u4dff\\U00010000\u9999\\U00020222");
            }
            if ((result = trie.Reset().NextForCodePoint(0x4dff)) != Result.NoValue || result != trie.Current ||
                (result = trie.NextForCodePoint(0x103ff)) != Result.FinalValue || result != trie.Current ||
                trie.GetValue() != 99999
                )
            {
                Errln("CharsTrie.NextForCodePoint() fails for " + data[2].s);
            }
        }
コード例 #4
0
ファイル: CharsTrieTest.cs プロジェクト: NightOwl888/ICU4N
        public void Test59IteratorFromChars()
        {
            StringAndValue[] data =
            {
                new StringAndValue("mm",     3),
                new StringAndValue("mmm",   33),
                new StringAndValue("mmnop", 333)
            };
            builder_.Clear();
            foreach (StringAndValue item in data)
            {
                builder_.Add(item.s, item.value);
            }
            ICharSequence trieChars = builder_.BuildCharSequence(TrieBuilderOption.Fast);

            checkIterator(CharsTrie.GetEnumerator(trieChars, 0, 0), data);
        }
コード例 #5
0
ファイル: CharsTrieTest.cs プロジェクト: NightOwl888/ICU4N
        public void Test50IteratorFromBranch()
        {
            CharsTrie trie = buildMonthsTrie(TrieBuilderOption.Fast);

            // Go to a branch node.
            trie.Next('j');
            trie.Next('a');
            trie.Next('n');
            CharsTrieEnumerator iter = trie.GetEnumerator();

            // Expected data: Same as in buildMonthsTrie(), except only the suffixes
            // following "jan".
            StringAndValue[] data =
            {
                new StringAndValue("",                             1),
                new StringAndValue(".",                            1),
                new StringAndValue("a",                            1),
                new StringAndValue("bb",                           1),
                new StringAndValue("c",                            1),
                new StringAndValue("ddd",                          1),
                new StringAndValue("ee",                           1),
                new StringAndValue("ef",                           1),
                new StringAndValue("f",                            1),
                new StringAndValue("gg",                           1),
                new StringAndValue("h",                            1),
                new StringAndValue("iiii",                         1),
                new StringAndValue("j",                            1),
                new StringAndValue("kk",                           1),
                new StringAndValue("kl",                           1),
                new StringAndValue("kmm",                          1),
                new StringAndValue("l",                            1),
                new StringAndValue("m",                            1),
                new StringAndValue("nnnnnnnnnnnnnnnnnnnnnnnnnnnn", 1),
                new StringAndValue("o",                            1),
                new StringAndValue("pp",                           1),
                new StringAndValue("qqq",                          1),
                new StringAndValue("r",                            1),
                new StringAndValue("uar",                          1),
                new StringAndValue("uary", 1)
            };
            checkIterator(iter, data);
            // Reset, and we should get the same result.
            Logln("after iter.Reset()");
            checkIterator(iter.Reset(), data);
        }
コード例 #6
0
ファイル: CharsTrieTest.cs プロジェクト: NightOwl888/ICU4N
        private void checkFirst(CharsTrie trie, StringAndValue[] data, int dataLength)
        {
            for (int i = 0; i < dataLength; ++i)
            {
                if (data[i].s.Length == 0)
                {
                    continue;  // skip empty string
                }
                String expectedString = data[i].s;
                int    c           = expectedString[0];
                int    nextCp      = expectedString.Length > 1 ? expectedString[1] : 0;
                Result firstResult = trie.First(c);
                int    firstValue  = firstResult.HasValue() ? trie.GetValue() : -1;
                Result nextResult  = trie.Next(nextCp);
                if (firstResult != trie.Reset().Next(c) ||
                    firstResult != trie.Current ||
                    firstValue != (firstResult.HasValue() ? trie.GetValue() : -1) ||
                    nextResult != trie.Next(nextCp)
                    )
                {
                    Errln(String.Format("trie.first(U+{0:X4})!=trie.Reset().Next(same) for {1}",
                                        c, data[i].s));
                }
                c = expectedString.CodePointAt(0);
                int cLength = Character.CharCount(c);
                nextCp = expectedString.Length > cLength?expectedString.CodePointAt(cLength) : 0;

                firstResult = trie.FirstForCodePoint(c);
                firstValue  = firstResult.HasValue() ? trie.GetValue() : -1;
                nextResult  = trie.NextForCodePoint(nextCp);
                if (firstResult != trie.Reset().NextForCodePoint(c) ||
                    firstResult != trie.Current ||
                    firstValue != (firstResult.HasValue() ? trie.GetValue() : -1) ||
                    nextResult != trie.NextForCodePoint(nextCp)
                    )
                {
                    Errln(String.Format("trie.firstForCodePoint(U+{0:X4})!=trie.Reset().NextForCodePoint(same) for {1}",
                                        c, data[i].s));
                }
            }
            trie.Reset();
        }
コード例 #7
0
ファイル: CharsTrieTest.cs プロジェクト: NightOwl888/ICU4N
 // next(string) is also tested in other functions,
 // but here we try to go partway through the string, and then beyond it.
 private void checkNextString(CharsTrie trie, StringAndValue[] data, int dataLength)
 {
     for (int i = 0; i < dataLength; ++i)
     {
         String expectedString = data[i].s;
         int    stringLength   = expectedString.Length;
         if (!trie.Next(expectedString, 0, stringLength / 2).Matches())
         {
             Errln("trie.Next(up to middle of string)=BytesTrie.Result.NO_MATCH for " + data[i].s);
             continue;
         }
         // Test that we stop properly at the end of the string.
         trie.Next(expectedString, stringLength / 2, stringLength);
         if (trie.Next(0).Matches())
         {
             Errln("trie.Next(string+NUL)!=BytesTrie.Result.NO_MATCH for " + data[i].s);
         }
         trie.Reset();
     }
 }
コード例 #8
0
ファイル: CharsTrieTest.cs プロジェクト: NightOwl888/ICU4N
        public void Test52TruncatingIteratorFromRoot()
        {
            CharsTrie           trie = buildMonthsTrie(TrieBuilderOption.Fast);
            CharsTrieEnumerator iter = trie.GetEnumerator(4);

            // Expected data: Same as in buildMonthsTrie(), except only the first 4 characters
            // of each string, and no string duplicates from the truncation.
            StringAndValue[] data =
            {
                new StringAndValue("augu", -1),
                new StringAndValue("jan",   1),
                new StringAndValue("jan.",  1),
                new StringAndValue("jana",  1),
                new StringAndValue("janb", -1),
                new StringAndValue("janc",  1),
                new StringAndValue("jand", -1),
                new StringAndValue("jane", -1),
                new StringAndValue("janf",  1),
                new StringAndValue("jang", -1),
                new StringAndValue("janh",  1),
                new StringAndValue("jani", -1),
                new StringAndValue("janj",  1),
                new StringAndValue("jank", -1),
                new StringAndValue("janl",  1),
                new StringAndValue("janm",  1),
                new StringAndValue("jann", -1),
                new StringAndValue("jano",  1),
                new StringAndValue("janp", -1),
                new StringAndValue("janq", -1),
                new StringAndValue("janr",  1),
                new StringAndValue("janu", -1),
                new StringAndValue("july",  7),
                new StringAndValue("jun",   6),
                new StringAndValue("jun.",  6),
                new StringAndValue("june", 6)
            };
            checkIterator(iter, data);
            // Reset, and we should get the same result.
            Logln("after iter.Reset()");
            checkIterator(iter.Reset(), data);
        }
コード例 #9
0
ファイル: CharsTrieTest.cs プロジェクト: NightOwl888/ICU4N
        public void Test40GetUniqueValue()
        {
            CharsTrie trie = buildMonthsTrie(TrieBuilderOption.Fast);
            long      uniqueValue;

            if ((uniqueValue = trie.GetUniqueValue()) != 0)
            {
                Errln("unique value at root");
            }
            trie.Next('j');
            trie.Next('a');
            trie.Next('n');
            // getUniqueValue() directly after next()
            if ((uniqueValue = trie.GetUniqueValue()) != ((1 << 1) | 1))
            {
                Errln("not unique value 1 after \"jan\": instead " + uniqueValue);
            }
            trie.First('j');
            trie.Next('u');
            if ((uniqueValue = trie.GetUniqueValue()) != 0)
            {
                Errln("unique value after \"ju\"");
            }
            if (trie.Next('n') != Result.IntermediateValue || 6 != trie.GetValue())
            {
                Errln("not normal value 6 after \"jun\"");
            }
            // getUniqueValue() after getValue()
            if ((uniqueValue = trie.GetUniqueValue()) != ((6 << 1) | 1))
            {
                Errln("not unique value 6 after \"jun\"");
            }
            // getUniqueValue() from within a linear-match node
            trie.First('a');
            trie.Next('u');
            if ((uniqueValue = trie.GetUniqueValue()) != ((8 << 1) | 1))
            {
                Errln("not unique value 8 after \"au\"");
            }
        }
コード例 #10
0
        public void Test51IteratorFromLinearMatch()
        {
            CharsTrie trie = buildMonthsTrie(StringTrieBuilder.Option.SMALL);

            // Go into a linear-match node.
            trie.Next('j');
            trie.Next('a');
            trie.Next('n');
            trie.Next('u');
            trie.Next('a');
            CharsTrie.Enumerator iter = trie.GetEnumerator();
            // Expected data: Same as in buildMonthsTrie(), except only the suffixes
            // following "janua".
            StringAndValue[] data =
            {
                new StringAndValue("r",  1),
                new StringAndValue("ry", 1)
            };
            checkIterator(iter, data);
            // Reset, and we should get the same result.
            Logln("after iter.Reset()");
            checkIterator(iter.Reset(), data);
        }
コード例 #11
0
        public void Test53TruncatingIteratorFromLinearMatchShort()
        {
            StringAndValue[] data =
            {
                new StringAndValue("abcdef",   10),
                new StringAndValue("abcdepq", 200),
                new StringAndValue("abcdeyz", 3000)
            };
            CharsTrie trie = buildTrie(data, data.Length, StringTrieBuilder.Option.FAST);

            // Go into a linear-match node.
            trie.Next('a');
            trie.Next('b');
            // Truncate within the linear-match node.
            CharsTrie.Enumerator iter     = trie.GetEnumerator(2);
            StringAndValue[]     expected =
            {
                new StringAndValue("cd", -1)
            };
            checkIterator(iter, expected);
            // Reset, and we should get the same result.
            Logln("after iter.Reset()");
            checkIterator(iter.Reset(), expected);
        }
コード例 #12
0
            public override BreakIterator WrapIteratorWithFilter(BreakIterator adoptBreakIterator)
            {
                if (filterSet.Count == 0)
                {
                    // Short circuit - nothing to except.
                    return(adoptBreakIterator);
                }

                CharsTrieBuilder builder  = new CharsTrieBuilder();
                CharsTrieBuilder builder2 = new CharsTrieBuilder();

                int revCount = 0;
                int fwdCount = 0;

                int subCount = filterSet.Count;

                ICharSequence[] ustrs    = new ICharSequence[subCount];
                int[]           partials = new int[subCount];

                CharsTrie backwardsTrie       = null; // i.e. ".srM" for Mrs.
                CharsTrie forwardsPartialTrie = null; // Has ".a" for "a.M."

                int i = 0;

                foreach (ICharSequence s in filterSet)
                {
                    ustrs[i]    = s; // copy by value?
                    partials[i] = 0; // default: no partial
                    i++;
                }

                for (i = 0; i < subCount; i++)
                {
                    string thisStr = ustrs[i].ToString();  // TODO: don't cast to String?
                    int    nn      = thisStr.IndexOf('.'); // TODO: non-'.' abbreviations
                    if (nn > -1 && (nn + 1) != thisStr.Length)
                    {
                        // is partial.
                        // is it unique?
                        int sameAs = -1;
                        for (int j = 0; j < subCount; j++)
                        {
                            if (j == i)
                            {
                                continue;
                            }
                            if (thisStr.RegionMatches(0, ustrs[j].ToString() /* TODO */, 0, nn + 1))
                            {
                                if (partials[j] == 0)
                                { // hasn't been processed yet
                                    partials[j] = SuppressInReverse | AddToForward;
                                }
                                else if ((partials[j] & SuppressInReverse) != 0)
                                {
                                    sameAs = j; // the other entry is already in the reverse table.
                                }
                            }
                        }

                        if ((sameAs == -1) && (partials[i] == 0))
                        {
                            StringBuilder prefix = new StringBuilder(thisStr.Substring(0, (nn + 1) - 0)); // ICU4N: Checked 2nd parameter
                                                                                                          // first one - add the prefix to the reverse table.
                            prefix.Reverse();
                            builder.Add(prefix, PARTIAL);
                            revCount++;
                            partials[i] = SuppressInReverse | AddToForward;
                        }
                    }
                }

                for (i = 0; i < subCount; i++)
                {
                    string thisStr = ustrs[i].ToString(); // TODO
                    if (partials[i] == 0)
                    {
                        StringBuilder reversed = new StringBuilder(thisStr).Reverse();
                        builder.Add(reversed, MATCH);
                        revCount++;
                    }
                    else
                    {
                        // an optimization would be to only add the portion after the '.'
                        // for example, for "Ph.D." we store ".hP" in the reverse table. We could just store "D." in the
                        // forward,
                        // instead of "Ph.D." since we already know the "Ph." part is a match.
                        // would need the trie to be able to hold 0-length strings, though.
                        builder2.Add(thisStr, MATCH); // forward
                        fwdCount++;
                    }
                }

                if (revCount > 0)
                {
                    backwardsTrie = builder.Build(StringTrieBuilder.Option.FAST);
                }

                if (fwdCount > 0)
                {
                    forwardsPartialTrie = builder2.Build(StringTrieBuilder.Option.FAST);
                }
                return(new SimpleFilteredSentenceBreakIterator(adoptBreakIterator, forwardsPartialTrie, backwardsTrie));
            }
コード例 #13
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.SentinelCodePoint, ce32))
            {
                AddContractionEntry(CollationFastLatin.CONTR_CHAR_MASK, ce0, ce1);
            }
            else
            {
                // Bail out for c-without-contraction.
                AddContractionEntry(CollationFastLatin.CONTR_CHAR_MASK, Collation.NoCE, 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 (CharsTrieEnumerator suffixes = CharsTrie.GetEnumerator(data.contexts, trieIndex + 2, 0))
            {
                while (suffixes.MoveNext())
                {
                    CharsTrieEntry 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.NoCE, 0);
                            addContraction = false;
                        }
                        continue;
                    }
                    if (addContraction)
                    {
                        AddContractionEntry(prevX, ce0, ce1);
                    }
                    ce32 = entry.Value;
                    if (suffix.Length == 1 && GetCEsFromCE32(data, Collation.SentinelCodePoint, ce32))
                    {
                        addContraction = true;
                    }
                    else
                    {
                        AddContractionEntry(x, Collation.NoCE, 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 | (uint)contractionIndex;
            ce1 = 0;
            return(true);
        }
コード例 #14
0
ファイル: TailoredSet.cs プロジェクト: SilentCC/ICU4N
 private void CompareContractions(int c, string p, int pidx, string q, int qidx) // ICU4N specific - changed p and q from ICharSequence to string
 {
     // Parallel iteration over suffixes of both tables.
     using (CharsTrie.Enumerator suffixes = new CharsTrie(p, pidx).GetEnumerator())
         using (CharsTrie.Enumerator baseSuffixes = new CharsTrie(q, qidx).GetEnumerator())
         {
             string ts = null; // Tailoring suffix.
             string bs = null; // Base suffix.
                               // Use a string with two U+FFFF as the limit sentinel.
                               // U+FFFF is untailorable and will not occur in contractions except maybe
                               // as a single suffix character for a root-collator boundary contraction.
             string          none = "\uffff\uffff";
             CharsTrie.Entry te = null, be = null;
             for (; ;)
             {
                 if (ts == null)
                 {
                     if (suffixes.MoveNext())
                     {
                         te = suffixes.Current;
                         ts = te.Chars.ToString();
                     }
                     else
                     {
                         te = null;
                         ts = none;
                     }
                 }
                 if (bs == null)
                 {
                     if (baseSuffixes.MoveNext())
                     {
                         be = baseSuffixes.Current;
                         bs = be.Chars.ToString();
                     }
                     else
                     {
                         be = null;
                         bs = none;
                     }
                 }
                 if (Utility.SameObjects(ts, none) && Utility.SameObjects(bs, none))
                 {
                     break;
                 }
                 int cmp = ts.CompareToOrdinal(bs);
                 if (cmp < 0)
                 {
                     // ts occurs in the tailoring but not in the base.
                     AddSuffix(c, ts);
                     te = null;
                     ts = null;
                 }
                 else if (cmp > 0)
                 {
                     // bs occurs in the base but not in the tailoring.
                     AddSuffix(c, bs);
                     be = null;
                     bs = null;
                 }
                 else
                 {
                     suffix = ts;
                     Compare(c, te.Value, be.Value);
                     suffix = null;
                     te     = be = null;
                     ts     = bs = null;
                 }
             }
         }
 }
コード例 #15
0
ファイル: TailoredSet.cs プロジェクト: SilentCC/ICU4N
 private void ComparePrefixes(int c, string p, int pidx, string q, int qidx) // ICU4N specific - changed p and q from ICharSequence to string
 {
     // Parallel iteration over prefixes of both tables.
     using (CharsTrie.Enumerator prefixes = new CharsTrie(p, pidx).GetEnumerator())
         using (CharsTrie.Enumerator basePrefixes = new CharsTrie(q, qidx).GetEnumerator())
         {
             string tp = null; // Tailoring prefix.
             string bp = null; // Base prefix.
                               // Use a string with a U+FFFF as the limit sentinel.
                               // U+FFFF is untailorable and will not occur in prefixes.
             string          none = "\uffff";
             CharsTrie.Entry te = null, be = null;
             for (; ;)
             {
                 if (tp == null)
                 {
                     if (prefixes.MoveNext())
                     {
                         te = prefixes.Current;
                         tp = te.Chars.ToString();
                     }
                     else
                     {
                         te = null;
                         tp = none;
                     }
                 }
                 if (bp == null)
                 {
                     if (basePrefixes.MoveNext())
                     {
                         be = basePrefixes.Current;
                         bp = be.Chars.ToString();
                     }
                     else
                     {
                         be = null;
                         bp = none;
                     }
                 }
                 if (Utility.SameObjects(tp, none) && Utility.SameObjects(bp, none))
                 {
                     break;
                 }
                 int cmp = tp.CompareToOrdinal(bp);
                 if (cmp < 0)
                 {
                     // tp occurs in the tailoring but not in the base.
                     Debug.Assert(te != null);
                     AddPrefix(data, tp, c, te.Value);
                     te = null;
                     tp = null;
                 }
                 else if (cmp > 0)
                 {
                     // bp occurs in the base but not in the tailoring.
                     Debug.Assert(be != null);
                     AddPrefix(baseData, bp, c, be.Value);
                     be = null;
                     bp = null;
                 }
                 else
                 {
                     SetPrefix(tp);
                     Debug.Assert(te != null && be != null);
                     Compare(c, te.Value, be.Value);
                     ResetPrefix();
                     te = be = null;
                     tp = bp = null;
                 }
             }
         }
 }
コード例 #16
0
ファイル: CharsTrieTest.cs プロジェクト: NightOwl888/ICU4N
        private void checkNextWithState(CharsTrie trie, StringAndValue[] data, int dataLength)
        {
            CharsTrieState noState = new CharsTrieState(), state = new CharsTrieState();

            for (int i = 0; i < dataLength; ++i)
            {
                if ((i & 1) == 0)
                {
                    try
                    {
                        trie.ResetToState(noState);
                        Errln("trie.resetToState(noState) should throw an ArgumentException");
                    }
                    catch (ArgumentException e)
                    {
                        // good
                    }
                }
                String expectedString = data[i].s;
                int    stringLength   = expectedString.Length;
                int    partialLength  = stringLength / 3;
                for (int j = 0; j < partialLength; ++j)
                {
                    if (!trie.Next(expectedString[j]).Matches())
                    {
                        Errln("trie.Next()=BytesTrie.Result.NO_MATCH for a prefix of " + data[i].s);
                        return;
                    }
                }
                trie.SaveState(state);
                Result resultAtState = trie.Current;
                Result result;
                int    valueAtState = -99;
                if (resultAtState.HasValue())
                {
                    valueAtState = trie.GetValue();
                }
                result = trie.Next(0);  // mismatch
                if (result != Result.NoMatch || result != trie.Current)
                {
                    Errln("trie.Next(0) matched after part of " + data[i].s);
                }
                if (resultAtState != trie.ResetToState(state).Current ||
                    (resultAtState.HasValue() && valueAtState != trie.GetValue())
                    )
                {
                    Errln("trie.Next(part of " + data[i].s + ") changes current()/getValue() after " +
                          "saveState/next(0)/resetToState");
                }
                else if (!(result = trie.Next(expectedString, partialLength, stringLength)).HasValue() ||
                         result != trie.Current)
                {
                    Errln("trie.Next(rest of " + data[i].s + ") does not seem to contain " + data[i].s + " after " +
                          "saveState/next(0)/resetToState");
                }
                else if (!(result = trie.ResetToState(state).
                                    Next(expectedString, partialLength, stringLength)).HasValue() ||
                         result != trie.Current)
                {
                    Errln("trie does not seem to contain " + data[i].s +
                          " after saveState/next(rest)/resetToState");
                }
                else if (trie.GetValue() != data[i].value)
                {
                    Errln(String.Format("trie value for {0} is {1}=0x{2:x} instead of expected {3}=0x{4:x}",
                                        data[i].s,
                                        trie.GetValue(), trie.GetValue(),
                                        data[i].value, data[i].value));
                }
                trie.Reset();
            }
        }
コード例 #17
0
ファイル: CharsTrieTest.cs プロジェクト: NightOwl888/ICU4N
        private void checkNext(CharsTrie trie, StringAndValue[] data, int dataLength)
        {
            CharsTrieState state = new CharsTrieState();

            for (int i = 0; i < dataLength; ++i)
            {
                String expectedString = data[i].s;
                int    stringLength   = expectedString.Length;
                Result result;
                if (!(result = trie.Next(expectedString, 0, stringLength)).HasValue() ||
                    result != trie.Current
                    )
                {
                    Errln("trie does not seem to contain " + data[i].s);
                }
                else if (trie.GetValue() != data[i].value)
                {
                    Errln(String.Format("trie value for {0} is {1}=0x{2:x} instead of expected {3}=0x{4:x}",
                                        data[i].s,
                                        trie.GetValue(), trie.GetValue(),
                                        data[i].value, data[i].value));
                }
                else if (result != trie.Current || trie.GetValue() != data[i].value)
                {
                    Errln("trie value for " + data[i].s + " changes when repeating current()/getValue()");
                }
                trie.Reset();
                result = trie.Current;
                for (int j = 0; j < stringLength; ++j)
                {
                    if (!result.HasNext())
                    {
                        Errln(String.Format("trie.Current!=hasNext before end of {0} (at index {1})",
                                            data[i].s, j));
                        break;
                    }
                    if (result == Result.IntermediateValue)
                    {
                        trie.GetValue();
                        if (trie.Current != Result.IntermediateValue)
                        {
                            Errln(String.Format("trie.getValue().Current!=Result.INTERMEDIATE_VALUE " +
                                                "before end of {0} (at index {1})", data[i].s, j));
                            break;
                        }
                    }
                    result = trie.Next(expectedString[j]);
                    if (!result.Matches())
                    {
                        Errln(String.Format("trie.Next()=Result.NO_MATCH " +
                                            "before end of {0} (at index {1})", data[i].s, j));
                        break;
                    }
                    if (result != trie.Current)
                    {
                        Errln(String.Format("trie.Next()!=following current() " +
                                            "before end of {0} (at index {1})", data[i].s, j));
                        break;
                    }
                }
                if (!result.HasValue())
                {
                    Errln("trie.Next()!=hasValue at the end of " + data[i].s);
                    continue;
                }
                trie.GetValue();
                if (result != trie.Current)
                {
                    Errln("trie.Current != current()+getValue()+current() after end of " +
                          data[i].s);
                }
                // Compare the final current() with whether next() can actually continue.
                trie.SaveState(state);
                bool nextContinues = false;
                for (int c = 0x20; c < 0xe000; ++c)
                {
                    if (c == 0x80)
                    {
                        c = 0xd800;  // Check for ASCII and surrogates but not all of the BMP.
                    }
                    if (trie.ResetToState(state).Next(c).Matches())
                    {
                        nextContinues = true;
                        break;
                    }
                }
                if ((result == Result.IntermediateValue) != nextContinues)
                {
                    Errln("(trie.Current==BytesTrie.Result.INTERMEDIATE_VALUE) contradicts " +
                          "(trie.Next(some char)!=BytesTrie.Result.NO_MATCH) after end of " + data[i].s);
                }
                trie.Reset();
            }
        }
コード例 #18
0
ファイル: CharsTrieTest.cs プロジェクト: NightOwl888/ICU4N
 private void checkIterator(CharsTrie trie, StringAndValue[] data, int dataLength)
 {
     checkIterator(trie.GetEnumerator(), data, dataLength);
 }