Пример #1
0
        /// <summary>
        /// Attempt to find a source-target/variant in the static locale
        /// resource store.  Do not perform fallback.  Return 0 on failure.
        /// <para/>
        /// On success, create a new entry object, register it in the dynamic
        /// store, and return a pointer to it, but do not make it public --
        /// just because someone requested something, we do not expand the
        /// available ID list (or spec DAG).
        /// </summary>
        private object[] FindInStaticStore(Spec src,
                                           Spec trg,
                                           string variant)
        {
            ////CLOVER:OFF
            if (DEBUG)
            {
                string ID = TransliteratorIDParser.STVtoID(src.Get(), trg.Get(), variant);
                Console.Out.WriteLine("TransliteratorRegistry.findInStaticStore:" +
                                      ID);
            }
            ////CLOVER:ON
            object[] entry = null;
            if (src.IsLocale)
            {
                entry = FindInBundle(src, trg, variant, Transliterator.Forward);
            }
            else if (trg.IsLocale)
            {
                entry = FindInBundle(trg, src, variant, Transliterator.Reverse);
            }

            // If we found an entry, store it in the Hashtable for next
            // time.
            if (entry != null)
            {
                RegisterEntry(src.Top, trg.Top, variant, entry, false);
            }

            return(entry);
        }
Пример #2
0
        /// <summary>
        /// Convenience method. Calls <see cref="RegisterEntry(string, string, string, string, object, bool)"/>.
        /// </summary>
        private void RegisterEntry(string ID,
                                   object entry,
                                   bool visible)
        {
            string[] stv = TransliteratorIDParser.IDtoSTV(ID);
            // Only need to do this if ID.indexOf('-') < 0
            string id = TransliteratorIDParser.STVtoID(stv[0], stv[1], stv[2]);

            RegisterEntry(id, stv[0], stv[1], stv[2], entry, visible);
        }
Пример #3
0
        /// <summary>
        /// Unregister an <paramref name="id"/>.  This removes an entry from the dynamic store
        /// if there is one.  The static locale resource store is
        /// unaffected.
        /// </summary>
        public virtual void Remove(string id)
        {
            string[] stv = TransliteratorIDParser.IDtoSTV(id);
            // Only need to do this if ID.indexOf('-') < 0
            string id2 = TransliteratorIDParser.STVtoID(stv[0], stv[1], stv[2]);

            registry.Remove(new CaseInsensitiveString(id2));
            RemoveSTV(stv[0], stv[1], stv[2]);
            availableIDs.Remove(new CaseInsensitiveString(id2));
        }
Пример #4
0
        /// <summary>
        /// Attempt to find a source-target/variant in the dynamic registry
        /// store.  Return 0 on failure.
        /// </summary>
        private object[] FindInDynamicStore(Spec src,
                                            Spec trg,
                                            string variant)
        {
            string ID = TransliteratorIDParser.STVtoID(src.Get(), trg.Get(), variant);

            ////CLOVER:OFF
            if (DEBUG)
            {
                Console.Out.WriteLine("TransliteratorRegistry.findInDynamicStore:" +
                                      ID);
            }
            ////CLOVER:ON
            return(registry.Get(new CaseInsensitiveString(ID)));
        }
Пример #5
0
        //----------------------------------------------------------------------
        // class TransliteratorRegistry: internal
        //----------------------------------------------------------------------

        /// <summary>
        /// Convenience method. Calls <see cref="RegisterEntry(string, string, string, string, object, bool)"/>.
        /// </summary>
        private void RegisterEntry(string source,
                                   string target,
                                   string variant,
                                   object entry,
                                   bool visible)
        {
            string s = source;

            if (s.Length == 0)
            {
                s = ANY;
            }
            string ID = TransliteratorIDParser.STVtoID(source, target, variant);

            RegisterEntry(ID, s, target, variant, entry, visible);
        }
Пример #6
0
        /// <summary>
        /// Registers standard transliterators with the system.  Called by
        /// <see cref="Transliterator"/> during initialization.  Scan all current targets
        /// and register those that are scripts T as Any-T/V.
        /// </summary>
        internal static void Register()
        {
            IDictionary <string, ISet <string> > seen = new Dictionary <string, ISet <string> >(); // old code used set, but was dependent on order

            foreach (string source in Transliterator.GetAvailableSources())
            {
                // Ignore the "Any" source
                if (source.Equals(ANY, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                foreach (string target in Transliterator.GetAvailableTargets(source))
                {
                    // Get the script code for the target.  If not a script, ignore.
                    int targetScript = ScriptNameToCode(target);
                    if (targetScript == UScript.InvalidCode)
                    {
                        continue;
                    }

                    ISet <string> seenVariants = seen.Get(target);
                    if (seenVariants == null)
                    {
                        seen[target] = seenVariants = new HashSet <string>();
                    }

                    foreach (string variant in Transliterator.GetAvailableVariants(source, target))
                    {
                        // Only process each target/variant pair once
                        if (seenVariants.Contains(variant))
                        {
                            continue;
                        }
                        seenVariants.Add(variant);

                        string id;
                        id = TransliteratorIDParser.STVtoID(ANY, target, variant);
                        AnyTransliterator trans = new AnyTransliterator(id, target, variant,
                                                                        targetScript);
                        Transliterator.RegisterInstance(trans);
                        Transliterator.RegisterSpecialInverse(target, NULL_ID, false);
                    }
                }
            }
        }