Пример #1
0
 /// <summary>
 /// This function is used by RBTableBuilder to fill in all the members of this
 /// object.  (Effectively, the builder class functions as a "friend" of this
 /// class, but to avoid changing too much of the logic, it carries around "shadow"
 /// copies of all these variables until the end of the build process and then
 /// copies them en masse into the actual tables object once all the construction
 /// logic is complete.  This function does that "copying en masse". </summary>
 /// <param name="f2ary"> The value for frenchSec (the French-secondary flag) </param>
 /// <param name="swap"> The value for SE Asian swapping rule </param>
 /// <param name="map"> The collator's character-mapping table (the value for mapping) </param>
 /// <param name="cTbl"> The collator's contracting-character table (the value for contractTable) </param>
 /// <param name="eTbl"> The collator's expanding-character table (the value for expandTable) </param>
 /// <param name="cFlgs"> The hash table of characters that participate in contracting-
 ///              character sequences (the value for contractFlags) </param>
 /// <param name="mso"> The value for maxSecOrder </param>
 /// <param name="mto"> The value for maxTerOrder </param>
 internal void FillInTables(bool f2ary, bool swap, UCompactIntArray map, List <List <EntryPair> > cTbl, List <int[]> eTbl, IntHashtable cFlgs, short mso, short mto)
 {
     outerInstance.FrenchSec_Renamed   = f2ary;
     outerInstance.SeAsianSwapping     = swap;
     outerInstance.Mapping             = map;
     outerInstance.ContractTable       = cTbl;
     outerInstance.ExpandTable         = eTbl;
     outerInstance.ContractFlags       = cFlgs;
     outerInstance.MaxSecOrder_Renamed = mso;
     outerInstance.MaxTerOrder_Renamed = mto;
 }
Пример #2
0
        /// <summary>
        /// Create a table-based collation object with the given rules.
        /// This is the main function that actually builds the tables and
        /// stores them back in the RBCollationTables object.  It is called
        /// ONLY by the RBCollationTables constructor. </summary>
        /// <seealso cref= RuleBasedCollator#RuleBasedCollator </seealso>
        /// <exception cref="ParseException"> If the rules format is incorrect. </exception>

//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void build(String pattern, int decmp) throws ParseException
        public void Build(String pattern, int decmp)
        {
            bool   isSource = true;
            int    i        = 0;
            String expChars;
            String groupChars;

            if (pattern.Length() == 0)
            {
                throw new ParseException("Build rules empty.", 0);
            }

            // This array maps Unicode characters to their collation ordering
            Mapping = new UCompactIntArray(RBCollationTables.UNMAPPED);
            // Normalize the build rules.  Find occurances of all decomposed characters
            // and normalize the rules before feeding into the builder.  By "normalize",
            // we mean that all precomposed Unicode characters must be converted into
            // a base character and one or more combining characters (such as accents).
            // When there are multiple combining characters attached to a base character,
            // the combining characters must be in their canonical order
            //
            // sherman/Note:
            //(1)decmp will be NO_DECOMPOSITION only in ko locale to prevent decompose
            //hangual syllables to jamos, so we can actually just call decompose with
            //normalizer's IGNORE_HANGUL option turned on
            //
            //(2)just call the "special version" in NormalizerImpl directly
            //pattern = Normalizer.decompose(pattern, false, Normalizer.IGNORE_HANGUL, true);
            //
            //Normalizer.Mode mode = CollatorUtilities.toNormalizerMode(decmp);
            //pattern = Normalizer.normalize(pattern, mode, 0, true);

            pattern = NormalizerImpl.canonicalDecomposeWithSingleQuotation(pattern);

            // Build the merged collation entries
            // Since rules can be specified in any order in the string
            // (e.g. "c , C < d , D < e , E .... C < CH")
            // this splits all of the rules in the string out into separate
            // objects and then sorts them.  In the above example, it merges the
            // "C < CH" rule in just before the "C < D" rule.
            //

            MPattern = new MergeCollation(pattern);

            int order = 0;

            // Now walk though each entry and add it to my own tables
            for (i = 0; i < MPattern.Count; ++i)
            {
                PatternEntry entry = MPattern.GetItemAt(i);
                if (entry != null)
                {
                    groupChars = entry.Chars;
                    if (groupChars.Length() > 1)
                    {
                        switch (groupChars.CharAt(groupChars.Length() - 1))
                        {
                        case '@':
                            FrenchSec  = true;
                            groupChars = groupChars.Substring(0, groupChars.Length() - 1);
                            break;

                        case '!':
                            SeAsianSwapping = true;
                            groupChars      = groupChars.Substring(0, groupChars.Length() - 1);
                            break;
                        }
                    }

                    order    = Increment(entry.Strength, order);
                    expChars = entry.Extension;

                    if (expChars.Length() != 0)
                    {
                        AddExpandOrder(groupChars, expChars, order);
                    }
                    else if (groupChars.Length() > 1)
                    {
                        char ch = groupChars.CharAt(0);
                        if (char.IsHighSurrogate(ch) && groupChars.Length() == 2)
                        {
                            AddOrder(Character.ToCodePoint(ch, groupChars.CharAt(1)), order);
                        }
                        else
                        {
                            AddContractOrder(groupChars, order);
                        }
                    }
                    else
                    {
                        char ch = groupChars.CharAt(0);
                        AddOrder(ch, order);
                    }
                }
            }
            AddComposedChars();

            Commit();
            Mapping.compact();

            /*
             * System.out.println("mappingSize=" + mapping.getKSize());
             * for (int j = 0; j < 0xffff; j++) {
             *  int value = mapping.elementAt(j);
             *  if (value != RBCollationTables.UNMAPPED)
             *      System.out.println("index=" + Integer.toString(j, 16)
             + ", value=" + Integer.toString(value, 16));
             + }
             */
            Tables.FillInTables(FrenchSec, SeAsianSwapping, Mapping, ContractTable, ExpandTable, ContractFlags, MaxSecOrder, MaxTerOrder);
        }