/// <summary> /// Creates a formatter from the pattern string. /// The number of arguments checked against the given limits is the /// highest argument number plus one, not the number of occurrences of arguments. /// </summary> /// <param name="pattern">The pattern string.</param> /// <param name="min">The pattern must have at least this many arguments.</param> /// <param name="max">The pattern must have at most this many arguments.</param> /// <returns>The new <see cref="SimpleFormatter"/> object.</returns> /// <exception cref="ArgumentException">For bad argument syntax and too few or too many arguments.</exception> /// <stable>ICU 57</stable> public static SimpleFormatter CompileMinMaxArguments(StringBuilder pattern, int min, int max) { StringBuilder sb = new StringBuilder(); string compiledPattern = SimpleFormatterImpl.CompileToStringMinMaxArguments(pattern, sb, min, max); return(new SimpleFormatter(compiledPattern)); }
public DataTableCultureDisplayNames(UCultureInfo culture, DisplayContextOptions options) #pragma warning disable 612, 618 : base() #pragma warning restore 612, 618 { this.displayContextOptions = options.Freeze(); this.langData = languageDataTableProvider.GetDataTable(culture, options.SubstituteHandling == SubstituteHandling.NoSubstitute); this.regionData = regionDataTableProvider.GetDataTable(culture, options.SubstituteHandling == SubstituteHandling.NoSubstitute); this.locale = langData.CultureInfo != null && langData.CultureInfo.Equals(CultureInfo.InvariantCulture) ? regionData.CultureInfo.ToUCultureInfo() : langData.CultureInfo.ToUCultureInfo(); // Note, by going through DataTable, this uses table lookup rather than straight lookup. // That should get us the same data, I think. This way we don't have to explicitly // load the bundle again. Using direct lookup didn't seem to make an appreciable // difference in performance. string sep = langData.Get("localeDisplayPattern", "separator"); if (sep == null || "separator".Equals(sep)) { sep = "{0}, {1}"; } StringBuilder sb = new StringBuilder(); this.separatorFormat = SimpleFormatterImpl.CompileToStringMinMaxArguments(sep, sb, 2, 2); string pattern = langData.Get("localeDisplayPattern", "pattern"); if (pattern == null || "pattern".Equals(pattern)) { pattern = "{0} ({1})"; } this.format = SimpleFormatterImpl.CompileToStringMinMaxArguments(pattern, sb, 2, 2); if (pattern.Contains("(")) { formatOpenParen = '('; formatCloseParen = ')'; formatReplaceOpenParen = '['; formatReplaceCloseParen = ']'; } else { formatOpenParen = '('; formatCloseParen = ')'; formatReplaceOpenParen = '['; formatReplaceCloseParen = ']'; } string keyTypePattern = langData.Get("localeDisplayPattern", "keyTypePattern"); if (keyTypePattern == null || "keyTypePattern".Equals(keyTypePattern)) { keyTypePattern = "{0}={1}"; } this.keyTypeFormat = SimpleFormatterImpl.CompileToStringMinMaxArguments( keyTypePattern, sb, 2, 2); // Get values from the contextTransforms data if we need them // Also check whether we will need a break iterator (depends on the data) bool needBrkIter = false; if (options.Capitalization == Capitalization.UIListOrMenu || options.Capitalization == Capitalization.Standalone) { capitalizationUsage = new bool[Enum.GetValues(typeof(CapitalizationContextUsage)).Length]; // initialized to all false ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.GetBundleInstance(ICUData.IcuBaseName, locale); CapitalizationContextSink sink = new CapitalizationContextSink(this); try { rb.GetAllItemsWithFallback("contextTransforms", sink); } catch (MissingManifestResourceException) { // Silently ignore. Not every locale has contextTransforms. } needBrkIter = sink.hasCapitalizationUsage; } // Get a sentence break iterator if we will need it if (needBrkIter || options.Capitalization == Capitalization.BeginningOfSentence) { capitalizationBrkIter = BreakIterator.GetSentenceInstance(locale); } this.currencyDisplayInfo = CurrencyData.Provider.GetInstance(locale, false); }