internal static NumberingSystem LookupInstanceByLocale(LocaleLookupData localeLookupData) { ULocale locale = localeLookupData.locale; ICUResourceBundle rb; try { rb = (ICUResourceBundle)UResourceBundle.GetBundleInstance(ICUData.IcuBaseName, locale); rb = rb.GetWithFallback("NumberElements"); } catch (MissingManifestResourceException) { return(new NumberingSystem()); } string numbersKeyword = localeLookupData.numbersKeyword; string resolvedNumberingSystem = null; for (; ;) { try { resolvedNumberingSystem = rb.GetStringWithFallback(numbersKeyword); break; } catch (MissingManifestResourceException) { // Fall back behavior as defined in TR35 if (numbersKeyword.Equals("native") || numbersKeyword.Equals("finance")) { numbersKeyword = "default"; } else if (numbersKeyword.Equals("traditional")) { numbersKeyword = "native"; } else { break; } } } NumberingSystem ns = null; if (resolvedNumberingSystem != null) { ns = GetInstanceByName(resolvedNumberingSystem); } if (ns == null) { ns = new NumberingSystem(); } return(ns); }
/// <summary> /// Returns the default numbering system for the specified <see cref="ULocale"/>. /// </summary> /// <stable>ICU 4.2</stable> public static NumberingSystem GetInstance(ULocale locale) { // Check for @numbers bool nsResolved = true; string numbersKeyword = locale.GetKeywordValue("numbers"); if (numbersKeyword != null) { foreach (string keyword in OTHER_NS_KEYWORDS) { if (numbersKeyword.Equals(keyword)) { nsResolved = false; break; } } } else { numbersKeyword = "default"; nsResolved = false; } if (nsResolved) { NumberingSystem ns = GetInstanceByName(numbersKeyword); if (ns != null) { return(ns); } // If the @numbers keyword points to a bogus numbering system name, // we return the default for the locale. numbersKeyword = "default"; } // Attempt to get the numbering system from the cache string baseName = locale.GetBaseName(); // TODO: Caching by locale+numbersKeyword could yield a large cache. // Try to load for each locale the mappings from OTHER_NS_KEYWORDS and default // to real numbering system names; can we get those from supplemental data? // Then look up those mappings for the locale and resolve the keyword. string key = baseName + "@numbers=" + numbersKeyword; LocaleLookupData localeLookupData = new LocaleLookupData(locale, numbersKeyword); return(cachedLocaleData.GetOrCreate(key, (k) => LookupInstanceByLocale(localeLookupData))); }
/// <summary> /// Factory method for creating a numbering system. /// </summary> /// <param name="name_in">The string representing the name of the numbering system.</param> /// <param name="radix_in">The radix for this numbering system. ICU currently /// supports only numbering systems whose radix is 10.</param> /// <param name="isAlgorithmic_in">Specifies whether the numbering system is algorithmic /// (true) or numeric (false).</param> /// <param name="desc_in">String used to describe the characteristics of the numbering /// system. For numeric systems, this string contains the digits used by the /// numbering system, in order, starting from zero. For algorithmic numbering /// systems, the string contains the name of the RBNF ruleset in the locale's /// NumberingSystemRules section that will be used to format numbers using /// this numbering system.</param> /// <stable>ICU 4.6</stable> private static NumberingSystem GetInstance(string name_in, int radix_in, bool isAlgorithmic_in, string desc_in) { if (radix_in < 2) { throw new ArgumentException("Invalid radix for numbering system"); } if (!isAlgorithmic_in) { if (desc_in.CodePointCount(0, desc_in.Length) != radix_in || !IsValidDigitString(desc_in)) { throw new ArgumentException("Invalid digit string for numbering system"); } } NumberingSystem ns = new NumberingSystem(); ns.radix = radix_in; ns.algorithmic = isAlgorithmic_in; ns.desc = desc_in; ns.name = name_in; return(ns); }