/// <summary> /// Return tif rhs is equal to this. /// </summary> /// /// <param name="rhs">the PluralRules to compare to.</param> /// <returns>true if this and rhs are equal.</returns> /// @draft ICU 3.8 /// @provisional This API might change or be removed in a future release. public bool Equals(PluralRules rhs) { if (rhs == null) { return(false); } if (rhs == this) { return(true); } if (!rhs.GetKeywords().Equals(keywords)) { return(false); } int limit = Math.Max(GetRepeatLimit(), rhs.GetRepeatLimit()); for (int i = 0; i < limit; ++i) { if (!Select(i).Equals(rhs.Select(i))) { return(false); } } return(true); }
/// <summary> /// Initializes the <c>PluralRules</c> object. Postcondition:<br/> /// <c>ulocale</c> : is <c>locale</c><br/> /// <c>pluralRules</c>: if <c>rules</c> != <c>null</c> it's /// set to rules, otherwise it is the predefined plural rule set for the /// locale <c>ulocale</c>.<br/> /// <c>parsedValues</c>: is <c>null</c><br/> /// <c>pattern</c>: is <c>null</c><br/> /// <c>numberFormat</c>: a <c>NumberFormat</c> for the locale /// <c>ulocale</c>. /// </summary> /// private void Init(PluralRules rules, ULocale locale) { ulocale = locale; pluralRules = (rules == null) ? IBM.ICU.Text.PluralRules.ForLocale(ulocale) : rules; parsedValues = null; pattern = null; numberFormat = IBM.ICU.Text.NumberFormat.GetInstance(ulocale); }
/// <summary> /// Creates a new <c>PluralFormat</c> for a given set of rules. The /// standard number formatting will be done using the given locale. /// </summary> /// /// <param name="ulocale_0">the default number formatting will be done using this locale.</param> /// <param name="rules">defines the behavior of the <c>PluralFormat</c> object.</param> /// @draft ICU 3.8 /// @provisional This API might change or be removed in a future release. public PluralFormat(ULocale ulocale_0, PluralRules rules) { this.ulocale = null; this.pluralRules = null; this.pattern = null; this.parsedValues = null; this.numberFormat = null; Init(rules, ulocale_0); }
/// <summary> /// Creates a new <c>PluralFormat</c> for a given set of rules. The /// standard number formatting will be done using the default locale. /// </summary> /// /// <param name="rules">defines the behavior of the <c>PluralFormat</c> object.</param> /// @draft ICU 3.8 /// @provisional This API might change or be removed in a future release. public PluralFormat(PluralRules rules) { this.ulocale = null; this.pluralRules = null; this.pattern = null; this.parsedValues = null; this.numberFormat = null; Init(rules, IBM.ICU.Util.ULocale.GetDefault()); }
/// <summary> /// Creates a new <c>PluralFormat</c> for a given set of rules, a /// pattern and a locale. /// </summary> /// /// <param name="ulocale_0">the <c>PluralFormat</c> will be configured with rulesfor this locale. This locale will also be used for standardnumber formatting.</param> /// <param name="rules">defines the behavior of the <c>PluralFormat</c> object.</param> /// <param name="pattern_1">the pattern for this <c>PluralFormat</c>.</param> /// <exception cref="IllegalArgumentException">if the pattern is invalid.</exception> /// @draft ICU 3.8 /// @provisional This API might change or be removed in a future release. public PluralFormat(ULocale ulocale_0, PluralRules rules, String pattern_1) { this.ulocale = null; this.pluralRules = null; this.pattern = null; this.parsedValues = null; this.numberFormat = null; Init(rules, ulocale_0); ApplyPattern(pattern_1); }
/// <summary> /// Creates a new <c>PluralFormat</c> for a given pattern string. The /// default locale will be used to get the set of plural rules and for /// standard number formatting. /// </summary> /// /// <param name="pattern_0">the pattern for this <c>PluralFormat</c>.</param> /// <exception cref="IllegalArgumentException">if the pattern is invalid.</exception> /// @draft ICU 3.8 /// @provisional This API might change or be removed in a future release. public PluralFormat(String pattern_0) { this.ulocale = null; this.pluralRules = null; this.pattern = null; this.parsedValues = null; this.numberFormat = null; Init(null, IBM.ICU.Util.ULocale.GetDefault()); ApplyPattern(pattern_0); }
// ------------------------------------------------------------------------- // Static class methods. // ------------------------------------------------------------------------- /// <summary> /// Provides access to the predefined <c>PluralRules</c> for a given /// locale. /// </summary> /// /// <param name="locale">The locale for which a <c>PluralRules</c> object isreturned.</param> /// <returns>The predefined <c>PluralRules</c> object for this locale. /// If there's no predefined rules for this locale, the rules for the /// closest parent in the locale hierarchy that has one will be /// returned. The final fallback always returns the default rules.</returns> /// @draft ICU 3.8 /// @provisional This API might change or be removed in a future release. public static PluralRules ForLocale(ULocale locale) { PluralRules result = null; while (null == (result = (PluralRules)ILOG.J2CsMapping.Collections.Collections.Get(ruleMap, locale.GetName()))) { locale = locale.GetFallback(); if (locale == null) { return(DEFAULT); } } return(result); }
static PluralRules() { String[] ruledata = { "other: n/ja,ko,tr,vi", "zero: n is 0; one: n is 1; two: n is 2; few: n in 3..10; " + "many: n in 11..99/ar", "one: n is 1/da,de,el,en,eo,es,et,fi,fo,he,hu,it,nb,nl,nn,no,pt,sv", "one: n in 0..1/fr,pt_BR", "zero: n is 0; one: n mod 10 is 1 and n mod 100 is not 11/lv", "one: n is 1; two: n is 2/ga", "zero: n is 0; one: n is 1; zero: n mod 100 in 1..19/ro", "other: n mod 100 in 11..19; one: n mod 10 is 1; " + "few: n mod 10 in 2..9/lt", "one: n mod 10 is 1 and n mod 100 is not 11; " + "few: n mod 10 in 2..4 " + "and n mod 100 not in 12..14/hr,ru,sr,uk", "one: n is 1; few: n in 2..4/cs,sk", "one: n is 1; few: n mod 10 in 2..4 and n mod 100 not in 12..14/pl", "one: n mod 100 is 1; two: n mod 100 is 2; " + "few: n mod 100 in 3..4/sl" }; Hashtable map = new Hashtable(); for (int i = 0; i < ruledata.Length; ++i) { String[] data = IBM.ICU.Impl.Utility.Split(ruledata[i], '/'); try { PluralRules pluralRules = ParseDescription(data[0]); String[] locales = IBM.ICU.Impl.Utility.Split(data[1], ','); for (int j = 0; j < locales.Length; ++j) { ILOG.J2CsMapping.Collections.Collections.Put(map, locales[j].Trim(), pluralRules); } } catch (Exception e) { System.Console.Error.WriteLine("PluralRules init failure, " + e.Message + " at line " + i); } } ruleMap = map; }