Пример #1
0
        public virtual CurrencyDisplayInfo GetInstance(UCultureInfo culture, bool withFallback)
        {
            // Make sure the locale is non-null (this can happen during deserialization):
            if (culture == null)
            {
                culture = UCultureInfo.InvariantCulture;
            }
            ICUCurrencyDisplayInfo instance = currencyDisplayInfoCache;

            if (instance == null || !culture.Equals(instance.culture) || instance.fallback != withFallback)
            {
                ICUResourceBundle rb;
                if (withFallback)
                {
                    rb = ICUResourceBundle.GetBundleInstance(ICUData.IcuCurrencyBaseName, culture, ICUResourceBundle.IcuDataAssembly, OpenType.LocaleDefaultRoot);
                }
                else
                {
                    try
                    {
                        rb = ICUResourceBundle.GetBundleInstance(ICUData.IcuCurrencyBaseName, culture, ICUResourceBundle.IcuDataAssembly, OpenType.LocaleOnly);
                    }
                    catch (MissingManifestResourceException)
                    {
                        return(null);
                    }
                }
                instance = new ICUCurrencyDisplayInfo(culture, rb, withFallback);
                currencyDisplayInfoCache = instance;
            }
            return(instance);
        }
Пример #2
0
        private void getFunctionalEquivalentTestCases(String path, Assembly cl, String resName, String keyword,
                                                      bool truncate, String[] testCases)
        {
            //String F_STR = "f";
            String T_STR = "t";

            bool[] isAvail = new bool[1];

            Logln("Testing functional equivalents...");
            for (int i = 0; i < testCases.Length; i += 3)
            {
                bool    expectAvail  = T_STR.Equals(testCases[i + 0]);
                ULocale inLocale     = new ULocale(testCases[i + 1]);
                ULocale expectLocale = new ULocale(testCases[i + 2]);

                Logln(((int)(i / 3)).ToString(CultureInfo.InvariantCulture) + ": " + expectAvail.ToString() + "\t\t" +
                      inLocale.ToString() + "\t\t" + expectLocale.ToString());

                ULocale equivLocale = ICUResourceBundle.GetFunctionalEquivalent(path, cl, resName, keyword, inLocale, isAvail, truncate);
                bool    gotAvail    = isAvail[0];

                if ((gotAvail != expectAvail) || !equivLocale.Equals(expectLocale))
                {
                    Errln(((int)(i / 3)).ToString(CultureInfo.InvariantCulture) + ":  Error, expected  Equiv=" + expectAvail.ToString() + "\t\t" +
                          inLocale.ToString() + "\t\t--> " + expectLocale.ToString() + ",  but got " + gotAvail.ToString() + " " +
                          equivLocale.ToString());
                }
            }
        }
Пример #3
0
 private static RootType GetRootType(string baseName, Assembly root)
 {
     return(ROOT_CACHE.GetOrAdd(baseName, (key) =>
     {
         string rootLocale = (baseName.IndexOf('.') == -1) ? "root" : "";
         try
         {
             ICUResourceBundle.GetBundleInstance(baseName, rootLocale, root, true);
             return RootType.ICU;
         }
         catch (MissingManifestResourceException)
         {
             try
             {
                 ResourceBundleWrapper.GetBundleInstance(baseName, rootLocale, root, true);
                 return RootType.DotNet;
             }
             catch (MissingManifestResourceException)
             {
                 //throw away the exception
                 return RootType.Missing;
             }
         }
     }));
 }
Пример #4
0
        private static RootType GetRootType(string baseName, Assembly root)
        {
            RootType rootType;

            if (!ROOT_CACHE.TryGetValue(baseName, out rootType))
            {
                string rootLocale = (baseName.IndexOf('.') == -1) ? "root" : "";
                try
                {
                    ICUResourceBundle.GetBundleInstance(baseName, rootLocale, root, true);
                    rootType = RootType.ICU;
                }
                catch (MissingManifestResourceException ex)
                {
                    try
                    {
                        ResourceBundleWrapper.GetBundleInstance(baseName, rootLocale, root, true);
                        rootType = RootType.JAVA;
                    }
                    catch (MissingManifestResourceException e)
                    {
                        //throw away the exception
                        rootType = RootType.MISSING;
                    }
                }

                ROOT_CACHE[baseName] = rootType;
            }

            return(rootType);
        }
Пример #5
0
        /// <summary>
        /// Returns LocaleDisplayPattern for this locale, e.g., {0}({1})
        /// </summary>
        /// <returns>Locale display pattern as a <see cref="string"/>.</returns>
        /// <stable>ICU 4.2</stable>
        public string GetLocaleDisplayPattern()
        {
            ICUResourceBundle locDispBundle        = (ICUResourceBundle)langBundle.Get(LOCALE_DISPLAY_PATTERN);
            string            localeDisplayPattern = locDispBundle.GetStringWithFallback(PATTERN);

            return(localeDisplayPattern);
        }
        public virtual CurrencyDisplayInfo GetInstance(ULocale locale, bool withFallback)
        {
            // Make sure the locale is non-null (this can happen during deserialization):
            if (locale == null)
            {
                locale = ULocale.ROOT;
            }
            ICUCurrencyDisplayInfo instance = currencyDisplayInfoCache;

            if (instance == null || !instance.locale.Equals(locale) || instance.fallback != withFallback)
            {
                ICUResourceBundle rb;
                if (withFallback)
                {
                    rb = ICUResourceBundle.GetBundleInstance(
                        ICUData.ICU_CURR_BASE_NAME, locale, typeof(ICUCurrencyDisplayInfoProvider).GetTypeInfo().Assembly, OpenType.LOCALE_DEFAULT_ROOT);
                }
                else
                {
                    try
                    {
                        rb = ICUResourceBundle.GetBundleInstance(
                            ICUData.ICU_CURR_BASE_NAME, locale, typeof(ICUCurrencyDisplayInfoProvider).GetTypeInfo().Assembly, OpenType.LOCALE_ONLY);
                    }
                    catch (MissingManifestResourceException e)
                    {
                        return(null);
                    }
                }
                instance = new ICUCurrencyDisplayInfo(locale, rb, withFallback);
                currencyDisplayInfoCache = instance;
            }
            return(instance);
        }
Пример #7
0
        /// <summary>
        /// <icu/> Loads a new resource bundle for the given base name, locale and assembly.
        /// Optionally will disable loading of fallback bundles.
        /// </summary>
        /// <param name="baseName">String containing the name of the data package.
        /// If null the default ICU package name is used.</param>
        /// <param name="localeName">The locale for which a resource bundle is desired.</param>
        /// <param name="root">The class object from which to load the resource bundle.</param>
        /// <param name="disableFallback">Disables loading of fallback lookup chain.</param>
        /// <exception cref="MissingManifestResourceException">If no resource bundle for the specified base name can be found.</exception>
        /// <returns>A resource bundle for the given base name and locale.</returns>
        /// <stable>ICU 3.0</stable>
        protected static UResourceBundle InstantiateBundle(string baseName, string localeName,
                                                           Assembly root, bool disableFallback)
        {
            RootType rootType = GetRootType(baseName, root);

            switch (rootType)
            {
            case RootType.ICU:
                return(ICUResourceBundle.GetBundleInstance(baseName, localeName, root, disableFallback));

            case RootType.DotNet:
                return(ResourceBundleWrapper.GetBundleInstance(baseName, localeName, root,
                                                               disableFallback));

            case RootType.Missing:
            default:
                UResourceBundle b;
                try
                {
                    b = ICUResourceBundle.GetBundleInstance(baseName, localeName, root,
                                                            disableFallback);
                    SetRootType(baseName, RootType.ICU);
                }
                catch (MissingManifestResourceException)
                {
                    b = ResourceBundleWrapper.GetBundleInstance(baseName, localeName, root,
                                                                disableFallback);
                    SetRootType(baseName, RootType.DotNet);
                }
                return(b);
            }
        }
Пример #8
0
 internal ResourceInt(String key, String resPath, long resource,
                      ICUResourceBundle bundle)
 {
     IBM.ICU.Impl.ICUResourceBundle.Assign(this, bundle);
     this.key      = key;
     this.resource = resource;
     this.resPath  = resPath;
 }
Пример #9
0
        // /CLOVER:ON

        /// <summary>
        /// Returns the set of exemplar characters for a locale.
        /// </summary>
        ///
        /// <param name="locale">Locale for which the exemplar character set is to beretrieved.</param>
        /// <param name="options">Bitmask for options to apply to the exemplar pattern. Specifyzero to retrieve the exemplar set as it is defined in thelocale data. Specify UnicodeSet.CASE to retrieve a case-foldedexemplar set. See <see cref="null"/>for a complete list of valid options. The IGNORE_SPACE bit isalways set, regardless of the value of 'options'.</param>
        /// <returns>The set of exemplar characters for the given locale.</returns>
        /// @stable ICU 3.0
        public static UnicodeSet GetExemplarSet(ULocale locale, int options)
        {
            ICUResourceBundle bundle_0 = (ICUResourceBundle)IBM.ICU.Util.UResourceBundle
                                         .GetBundleInstance(IBM.ICU.Impl.ICUResourceBundle.ICU_BASE_NAME, locale);
            String pattern = bundle_0.GetString(EXEMPLAR_CHARS);

            return(new UnicodeSet(pattern, IBM.ICU.Text.UnicodeSet.IGNORE_SPACE | options));
        }
Пример #10
0
 internal override UCultureInfo[] GetUCultures(UCultureTypes types) // ICU4N: Renamed from GetAvailableULocales
 {
     if (service.IsDefault)
     {
         return(ICUResourceBundle.GetUCultures(types));
     }
     return(service.GetUCultures(types));
 }
Пример #11
0
 internal override ULocale[] GetAvailableULocales()
 {
     if (service.IsDefault)
     {
         return(ICUResourceBundle.GetAvailableULocales());
     }
     return(service.GetAvailableULocales());
 }
Пример #12
0
        /// <summary>
        /// Utility to fetch locale display data from resource bundle tables.  Convenience
        /// wrapper for <see cref="GetTableString(ICUResourceBundle, string, string, string, string)"/>.
        /// </summary>
        public static string GetTableString(string path, ULocale locale, string tableName,
                                            string itemName, string defaultValue)
        {
            ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.
                                       GetBundleInstance(path, locale.GetBaseName());

            return(GetTableString(bundle, tableName, null, itemName, defaultValue));
        }
Пример #13
0
#pragma warning disable 809
        internal override ISet <string> KeySet() // ICU4N specific - marked internal instead of protected, since the functionality is obsolete
#pragma warning disable 809
        {
            // TODO: Java 6 ResourceBundle has keySet() which calls handleKeySet()
            // and caches the results.
            // When we upgrade to Java 6, we still need to check for isTopLevelResource().
            // Keep the else branch as is. The if body should just return super.keySet().
            // Remove then-redundant caching of the keys.
            ISet <string>     keys  = null;
            ICUResourceBundle icurb = null;

            if (IsTopLevelResource && this is ICUResourceBundle)
            {
                // We do not cache the top-level keys in this base class so that
                // not every string/int/binary... resource has to have a keys cache field.
                icurb = (ICUResourceBundle)this;
                keys  = icurb.TopLevelKeySet;
            }
            if (keys == null)
            {
                if (IsTopLevelResource)
                {
                    SortedSet <string> newKeySet;
                    if (m_parent == null)
                    {
                        newKeySet = new SortedSet <string>();
                    }
                    else if (m_parent is UResourceBundle)
                    {
                        newKeySet = new SortedSet <string>(((UResourceBundle)m_parent).KeySet());
                    }
                    else
                    {
                        // TODO: Java 6 ResourceBundle has keySet(); use it when we upgrade to Java 6
                        // and remove this else branch.
                        newKeySet = new SortedSet <string>();
                        using (var parentKeys = Parent.GetKeys().GetEnumerator())
                        {
                            while (parentKeys.MoveNext())
                            {
                                newKeySet.Add(parentKeys.Current);
                            }
                        }
                    }
                    newKeySet.UnionWith(HandleKeySet());
                    keys = (newKeySet).AsReadOnly();
                    if (icurb != null)
                    {
                        icurb.TopLevelKeySet = keys;
                    }
                }
                else
                {
                    return(HandleKeySet());
                }
            }
            return(keys);
        }
Пример #14
0
        /// <summary>
        /// Returns the display name for the given currency in the given locale. For
        /// example, the display name for the USD currency object in the en_US locale
        /// is "$".
        /// </summary>
        ///
        /// <param name="locale">locale in which to display currency</param>
        /// <param name="nameStyle">selector for which kind of name to return</param>
        /// <param name="isChoiceFormat">fill-in; isChoiceFormat[0] is set to true if the returnedvalue is a ChoiceFormat pattern; otherwise it is set to false</param>
        /// <returns>display string for this currency. If the resource data contains
        /// no entry for this currency, then the ISO 4217 code is returned.
        /// If isChoiceFormat[0] is true, then the result is a ChoiceFormat
        /// pattern. Otherwise it is a static string.</returns>
        /// @stable ICU 3.2
        public String GetName(ULocale locale, int nameStyle,
                              bool[] isChoiceFormat)
        {
            // Look up the Currencies resource for the given locale. The
            // Currencies locale data looks like this:
            // |en {
            // | Currencies {
            // | USD { "US$", "US Dollar" }
            // | CHF { "Sw F", "Swiss Franc" }
            // | INR { "=0#Rs|1#Re|1<Rs", "=0#Rupees|1#Rupee|1<Rupees" }
            // | //...
            // | }
            // |}

            if (nameStyle < 0 || nameStyle > 1)
            {
                throw new ArgumentException();
            }

            String s = null;

            try {
                UResourceBundle rb = IBM.ICU.Util.UResourceBundle.GetBundleInstance(
                    IBM.ICU.Impl.ICUResourceBundle.ICU_BASE_NAME, locale);
                ICUResourceBundle currencies = (ICUResourceBundle)rb
                                               .Get("Currencies");

                // Fetch resource with multi-level resource inheritance fallback
                s = currencies.GetWithFallback(isoCode).GetString(nameStyle);
            } catch (MissingManifestResourceException e) {
                // TODO what should be done here?
            }

            // Determine if this is a ChoiceFormat pattern. One leading mark
            // indicates a ChoiceFormat. Two indicates a static string that
            // starts with a mark. In either case, the first mark is ignored,
            // if present. Marks in the rest of the string have no special
            // meaning.
            isChoiceFormat[0] = false;
            if (s != null)
            {
                int i = 0;
                while (i < s.Length && s[i] == '=' && i < 2)
                {
                    ++i;
                }
                isChoiceFormat[0] = (i == 1);
                if (i != 0)
                {
                    // Skip over first mark
                    s = s.Substring(1);
                }
                return(s);
            }

            // If we fail to find a match, use the ISO 4217 code
            return(isoCode);
        }
Пример #15
0
        public override ISet <string> KeySet() // ICU4N TODO: API - change to KeySet property
        {
            // TODO: Java 6 ResourceBundle has keySet() which calls handleKeySet()
            // and caches the results.
            // When we upgrade to Java 6, we still need to check for isTopLevelResource().
            // Keep the else branch as is. The if body should just return super.keySet().
            // Remove then-redundant caching of the keys.
            ISet <string>     keys  = null;
            ICUResourceBundle icurb = null;

            if (IsTopLevelResource && this is ICUResourceBundle)
            {
                // We do not cache the top-level keys in this base class so that
                // not every string/int/binary... resource has to have a keys cache field.
                icurb = (ICUResourceBundle)this;
                keys  = icurb.TopLevelKeySet;
            }
            if (keys == null)
            {
                if (IsTopLevelResource)
                {
                    SortedSet <string> newKeySet;
                    if (parent == null)
                    {
                        newKeySet = new SortedSet <string>();
                    }
                    else if (parent is UResourceBundle)
                    {
                        newKeySet = new SortedSet <string>(((UResourceBundle)parent).KeySet());
                    }
                    else
                    {
                        // TODO: Java 6 ResourceBundle has keySet(); use it when we upgrade to Java 6
                        // and remove this else branch.
                        newKeySet = new SortedSet <string>();
                        using (var parentKeys = Parent.GetKeys().GetEnumerator())
                        {
                            while (parentKeys.MoveNext())
                            {
                                newKeySet.Add(parentKeys.Current);
                            }
                        }
                    }
                    newKeySet.UnionWith(HandleKeySet());
                    keys = (newKeySet).ToUnmodifiableSet();
                    if (icurb != null)
                    {
                        icurb.TopLevelKeySet = keys;
                    }
                }
                else
                {
                    return(HandleKeySet());
                }
            }
            return(keys);
        }
Пример #16
0
 internal ResourceString(String key, String resPath, long resource,
                         ICUResourceBundle bundle)
 {
     IBM.ICU.Impl.ICUResourceBundle.Assign(this, bundle);
     value_ren     = GetStringValue(resource);
     this.key      = key;
     this.resource = resource;
     this.resPath  = resPath;
 }
Пример #17
0
 internal ResourceArray(String key, String resPath, long resource,
                        ICUResourceBundle bundle)
 {
     IBM.ICU.Impl.ICUResourceBundle.Assign(this, bundle);
     this.resource = resource;
     this.key      = key;
     this.size     = CountItems();
     this.resPath  = resPath;
 }
Пример #18
0
        /// <summary>
        /// Override of superclass method.
        /// </summary>
        public override void UpdateVisibleIDs(IDictionary <string, IServiceFactory> result)
        {
            ISet <string> visibleIDs = ICUResourceBundle.GetAvailableLocaleNameSet(bundleName, Assembly); // only visible ids

            foreach (string id in visibleIDs)
            {
                result[id] = this;
            }
        }
Пример #19
0
        /// <summary>
        /// Returns the string in a given resource at the specified index.
        /// </summary>
        ///
        /// <param name="index">an index to the wanted string.</param>
        /// <returns>a string which lives in the resource.</returns>
        /// <exception cref="IndexOutOfBoundsException"></exception>
        /// <exception cref="UResourceTypeMismatchException"></exception>
        /// @draft ICU 3.8
        /// @provisional This API might change or be removed in a future release.
        public String GetString(int index)
        {
            ICUResourceBundle temp = (ICUResourceBundle)Get(index);

            if (temp.GetType() == STRING)
            {
                return(temp.GetString());
            }
            throw new UResourceTypeMismatchException("");
        }
Пример #20
0
        /// <summary>
        /// Returns the string in a given resource at the specified index.
        /// </summary>
        /// <param name="index">An index to the wanted string.</param>
        /// <returns>A string which lives in the resource.</returns>
        /// <exception cref="IndexOutOfRangeException">If the index value is out of bounds of accepted values.</exception>
        /// <exception cref="UResourceTypeMismatchException">If resource bundle type mismatch.</exception>
        /// <stable>ICU 3.8</stable>
        public virtual string GetString(int index)
        {
            ICUResourceBundle temp = (ICUResourceBundle)Get(index);

            if (temp.Type == UResourceType.String)
            {
                return(temp.GetString());
            }
            throw new UResourceTypeMismatchException("");
        }
Пример #21
0
 internal ResourceIntVector(String key, String resPath, long resource,
                            ICUResourceBundle bundle)
 {
     IBM.ICU.Impl.ICUResourceBundle.Assign(this, bundle);
     this.key      = key;
     this.resource = resource;
     this.size     = 1;
     this.resPath  = resPath;
     value_ren     = GetValue();
 }
Пример #22
0
 public override UCultureInfo[] GetUCultures(UCultureTypes types) // ICU4N: Renamed from GetAvailableLocales
 {
     if (service == null)
     {
         return(ICUResourceBundle.GetUCultures(types));
     }
     else
     {
         return(service.GetUCultures(types));
     }
 }
Пример #23
0
 public override ULocale[] GetAvailableULocales()
 {
     if (service == null)
     {
         return(ICUResourceBundle.GetAvailableULocales());
     }
     else
     {
         return(service.GetAvailableULocales());
     }
 }
Пример #24
0
            private static ISet <string> LoadSupportedIDs()
            {
                HashSet <string> result = new HashSet <string>();

                result.UnionWith(ICUResourceBundle.GetAvailableLocaleNameSet());
                result.Add(californio);
                result.Add(valley);
                result.Add(surfer);
                result.Add(geek);
                return(result.AsReadOnly());
            }
Пример #25
0
        /// <summary>
        /// Retrieves a delimiter string from the locale data.
        /// </summary>
        /// <param name="type">
        /// The type of delimiter string desired.  Currently,
        /// the valid choices are <see cref="DelimiterType.QuotationStart"/>, <see cref="DelimiterType.QuotationEnd"/>,
        /// <see cref="DelimiterType.AlternateQuotationStart"/>, or <see cref="DelimiterType.AlternateQuotationEnd"/>.
        /// </param>
        /// <returns>The desired delimiter string.</returns>
        /// <stable>ICU 3.4</stable>
        public string GetDelimiter(DelimiterType type)
        {
            ICUResourceBundle delimitersBundle = (ICUResourceBundle)bundle.Get("delimiters");
            // Only some of the quotation marks may be here. So we make sure that we do a multilevel fallback.
            ICUResourceBundle stringBundle = delimitersBundle.GetWithFallback(DELIMITER_TYPES[(int)type]);

            if (noSubstitute && !bundle.IsRoot && stringBundle.IsRoot)
            {
                return(null);
            }
            return(stringBundle.GetString());
        }
Пример #26
0
 internal void Initialize(String key, String resPath, long resource,
                          ICUResourceBundle bundle, bool isTopLevel)
 {
     if (bundle != null)
     {
         IBM.ICU.Impl.ICUResourceBundle.Assign(this, bundle);
     }
     this.key        = key;
     this.resource   = resource;
     this.isTopLevel = isTopLevel;
     this.size       = CountItems();
     this.resPath    = resPath;
 }
Пример #27
0
        /// <summary>
        /// Instantiate a currency from a resource bundle found in Locale loc.
        /// </summary>
        ///
        /* package */ static internal Currency CreateCurrency(ULocale loc)
        {
            String country   = loc.GetCountry();
            String variant   = loc.GetVariant();
            bool   isPreEuro = variant.Equals("PREEURO");
            bool   isEuro    = variant.Equals("EURO");
            // TODO: ICU4C has service registration, and the currency is requested
            // from the service here.
            ICUResourceBundle bundle = (ICUResourceBundle)IBM.ICU.Util.UResourceBundle
                                       .GetBundleInstance(IBM.ICU.Impl.ICUResourceBundle.ICU_BASE_NAME,
                                                          "supplementalData",
                                                          IBM.ICU.Impl.ICUResourceBundle.ICU_DATA_CLASS_LOADER);

            if (bundle == null)
            {
                // throw new MissingResourceException()
                return(null);
            }
            try {
                UResourceBundle cm           = bundle.Get("CurrencyMap");
                String          curriso      = null;
                UResourceBundle countryArray = cm.Get(country);
                // Some regions can have more than one current currency in use.
                // The latest default currency is always the first one.
                UResourceBundle currencyReq = countryArray.Get(0);
                curriso = currencyReq.GetString("id");
                if (isPreEuro && curriso.Equals(EUR_STR))
                {
                    currencyReq = countryArray.Get(1);
                    curriso     = currencyReq.GetString("id");
                }
                else if (isEuro)
                {
                    curriso = EUR_STR;
                }
                if (curriso != null)
                {
                    return(new Currency(curriso));
                }
            } catch (MissingManifestResourceException ex) {
                // We don't know about this region.
                // As of CLDR 1.5.1, the data includes deprecated region history
                // too.
                // So if we get here, either the region doesn't exist, or the data
                // is really bad.
                // Deprecated regions should return the last valid currency for that
                // region in the data.
                // We don't try to resolve it to a new region.
            }
            return(null);
        }
Пример #28
0
            public Spec(string theSpec)
            {
                top        = theSpec;
                spec       = null;
                scriptName = null;
                try
                {
                    // Canonicalize script name.  If top is a script name then
                    // script != UScript.INVALID_CODE.
                    int script = UScript.GetCodeFromName(top);

                    // Canonicalize script name -or- do locale->script mapping
                    int[] s = UScript.GetCode(top);
                    if (s != null)
                    {
                        scriptName = UScript.GetName(s[0]);
                        // If the script name is the same as top then it's redundant
                        if (scriptName.Equals(top, StringComparison.OrdinalIgnoreCase))
                        {
                            scriptName = null;
                        }
                    }

                    isSpecLocale = false;
                    res          = null;
                    // If 'top' is not a script name, try a locale lookup
                    if (script == UScript.InvalidCode)
                    {
                        // ICU4N specific - CultureInfo doesn't support IANA culture names, so we use ULocale instead.
                        ULocale toploc = new ULocale(top);

                        //CultureInfo toploc = LocaleUtility.GetLocaleFromName(top);
                        res = (ICUResourceBundle)UResourceBundle.GetBundleInstance(ICUData.IcuTransliteratorBaseName, toploc, Transliterator.ICU_DATA_CLASS_LOADER);
                        // Make sure we got the bundle we wanted; otherwise, don't use it
                        if (res != null && LocaleUtility.IsFallbackOf(res.GetULocale().ToString(), top))
                        {
                            isSpecLocale = true;
                        }
                    }
                }
                catch (MissingManifestResourceException)
                {
                    ////CLOVER:OFF
                    // The constructor is called from multiple private methods
                    //  that protects an invalid scriptName
                    scriptName = null;
                    ////CLOVER:ON
                }
                // assert(spec != top);
                Reset();
            }
Пример #29
0
        public static DictionaryMatcher LoadDictionaryFor(string dictType)
        {
            ICUResourceBundle rb           = (ICUResourceBundle)UResourceBundle.GetBundleInstance(ICUData.IcuBreakIteratorBaseName); // com/ibm/icu/impl/data/icudt60b/brkitr
            string            dictFileName = rb.GetStringWithFallback("dictionaries/" + dictType);

            // ICU4N TODO: Possibly rename the above and use this syntax instead...?
            //var rm = new ResourceManager(ICUData.ICU_BRKITR_BASE_NAME, typeof(DictionaryData).GetTypeInfo().Assembly);
            //string dictFileName = rm.GetString("dictionaries_" + dictType);

            dictFileName = ICUData.IcuBreakIteratorName + '/' + dictFileName;
            ByteBuffer bytes = ICUBinary.GetRequiredData(dictFileName);

            ICUBinary.ReadHeader(bytes, DATA_FORMAT_ID, null);
            int[] indexes = new int[IX_COUNT];
            // TODO: read indexes[IX_STRING_TRIE_OFFSET] first, then read a variable-length indexes[]
            for (int i = 0; i < IX_COUNT; i++)
            {
                indexes[i] = bytes.GetInt32();
            }
            int offset = indexes[IX_STRING_TRIE_OFFSET];

            Assert.Assrt(offset >= (4 * IX_COUNT));
            if (offset > (4 * IX_COUNT))
            {
                int diff = offset - (4 * IX_COUNT);
                ICUBinary.SkipBytes(bytes, diff);
            }
            int trieType        = indexes[IX_TRIE_TYPE] & TRIE_TYPE_MASK;
            int totalSize       = indexes[IX_TOTAL_SIZE] - offset;
            DictionaryMatcher m = null;

            if (trieType == TRIE_TYPE_BYTES)
            {
                int    transform = indexes[IX_TRANSFORM];
                byte[] data      = new byte[totalSize];
                bytes.Get(data);
                m = new BytesDictionaryMatcher(data, transform);
            }
            else if (trieType == TRIE_TYPE_UCHARS)
            {
                Assert.Assrt(totalSize % 2 == 0);
                string data = ICUBinary.GetString(bytes, totalSize / 2, totalSize & 1);
                m = new CharsDictionaryMatcher(data);
            }
            else
            {
                m = null;
            }
            return(m);
        }
Пример #30
0
        private NamePrepTransform()
        {
            // load the resource bundle
            //ICUResourceBundle bundle = (ICUResourceBundle)ICUResourceBundle.GetBundleInstance("com/ibm/icu/dev/data/testdata", "idna_rules", typeof(NamePrepTransform).GetTypeInfo().Assembly, true);
            ICUResourceBundle bundle   = (ICUResourceBundle)ICUResourceBundle.GetBundleInstance("Dev/Data/TestData", "idna_rules", typeof(NamePrepTransform).GetTypeInfo().Assembly, true);
            String            mapRules = bundle.GetString("MapNoNormalization");

            mapRules += bundle.GetString("MapNFKC");
            // disable
            mapTransform      = new MapTransform("CaseMap", mapRules, 0 /*Transliterator.FORWARD*/);
            labelSeparatorSet = new UnicodeSet(bundle.GetString("LabelSeparatorSet"));
            prohibitedSet     = new UnicodeSet(bundle.GetString("ProhibitedSet"));
            unassignedSet     = new UnicodeSet(bundle.GetString("UnassignedSet"));
        }