/// <summary> /// Internal method to see if <start,*> values are all the same. /// </summary> internal StandardPlural?StartSame(StandardPlural start, IList <StandardPlural> endDone, out bool emit) { emit = false; StandardPlural?first = null; foreach (StandardPlural end in StandardPluralUtil.Values) { StandardPlural?item = Get(start, end); if (item == null) { continue; } if (first == null) { first = item; continue; } if (first != item) { return(null); } // only emit if we didn't cover with the 'end' values if (!endDone.Contains(end)) { emit = true; } } return(first); }
/// <summary> /// Internal method for setting; throws exception if already set. /// </summary> internal void SetIfNew(StandardPlural start, StandardPlural end, StandardPlural result) { sbyte old = data[(int)start * StandardPluralUtil.Count + (int)end]; if (old >= 0) { throw new ArgumentException("Previously set value for <" + start + ", " + end + ", " + StandardPluralUtil.Values[old] + ">"); } data[(int)start * StandardPluralUtil.Count + (int)end] = /*result == null ? (sbyte)-1 :*/ (sbyte)result; }
/// <summary> /// Returns the plural form corresponding to the keyword. /// </summary> /// <param name="keyword">Keyword for example "few" or "other".</param> /// <param name="result">>When this method returns, contains the index of the plural form corresponding to the keyword, otherwise /// <see cref="T:default(StandardPlural)"/>. This parameter is passed uninitialized.</param> /// <returns><c>true</c> if the <paramref name="keyword"/> is valid; otherwise <c>false</c>.</returns> internal static bool TryFromString(ICharSequence keyword, out StandardPlural result) { StandardPlural?p = OrNullFromString(keyword); if (p != null) { result = p.Value; return(true); } else { result = default(StandardPlural); return(false); } }
/// <summary> /// Returns the plural form corresponding to the keyword. /// </summary> /// <param name="keyword">Keyword for example "few" or "other".</param> /// <param name="result">>When this method returns, contains the index of the plural form corresponding to the keyword, otherwise /// <see cref="T:default(StandardPlural)"/>. This parameter is passed uninitialized.</param> /// <returns><c>true</c> if the <paramref name="keyword"/> is valid; otherwise <c>false</c>.</returns> public static bool TryFromString(char[] keyword, out StandardPlural result) { StandardPlural?p = OrNullFromString(keyword); if (p != null) { result = p.Value; return(true); } else { result = default(StandardPlural); return(false); } }
/// <summary> /// The lowercase CLDR keyword string for the plural form. /// </summary> /// <param name="standardPlural">This <see cref="StandardPlural"/>.</param> /// <returns>The lowercase CLDR keyword string for the plural form.</returns> public static string GetKeyword(this StandardPlural standardPlural) { switch (standardPlural) { case StandardPlural.Zero: return("zero"); case StandardPlural.One: return("one"); case StandardPlural.Two: return("two"); case StandardPlural.Few: return("few"); case StandardPlural.Many: return("many"); case StandardPlural.Other: return("other"); default: throw new ArgumentOutOfRangeException(nameof(standardPlural)); } }
public void Add(StandardPlural rangeStart, StandardPlural rangeEnd, StandardPlural result) { if (isFrozen) { throw new InvalidOperationException(); } @explicit[(int)result] = true; // ICU4N TODO: API Need to work out whether we should nullify or add another element to StandardPlural enum if (rangeStart == null) { foreach (StandardPlural rs in Enum.GetValues(typeof(StandardPlural))) { if (rangeEnd == null) { foreach (StandardPlural re in Enum.GetValues(typeof(StandardPlural))) { matrix.SetIfNew(rs, re, result); } } else { @explicit[(int)rangeEnd] = true; matrix.SetIfNew(rs, rangeEnd, result); } } } else if (rangeEnd == null) { @explicit[(int)rangeStart] = true; foreach (StandardPlural re in Enum.GetValues(typeof(StandardPlural))) { matrix.SetIfNew(rangeStart, re, result); } } else { @explicit[(int)rangeStart] = true; @explicit[(int)rangeEnd] = true; matrix.SetIfNew(rangeStart, rangeEnd, result); } }
/// <summary> /// Internal method to see if <*,end> values are all the same. /// </summary> internal StandardPlural?EndSame(StandardPlural end) { StandardPlural?first = null; foreach (StandardPlural start in StandardPluralUtil.Values) { StandardPlural?item = Get(start, end); if (item == null) { continue; } if (first == null) { first = item; continue; } if (first != item) { return(null); } } return(first); }
/// <summary> /// Internal method for getting. /// </summary> internal StandardPlural?Get(StandardPlural start, StandardPlural end) { sbyte result = data[(int)start * StandardPluralUtil.Count + (int)end]; return(result < 0 ? (StandardPlural?)null : StandardPluralUtil.Values[result]); }
/// <summary> /// Internal method for setting. /// </summary> internal void Set(StandardPlural start, StandardPlural end, StandardPlural result) { data[(int)start * StandardPluralUtil.Count + (int)end] = /*result == null ? (sbyte)-1 :*/ (sbyte)result; }
public bool IsExplicitlySet(StandardPlural count) { return(@explicit[(int)count]); }
public bool IsExplicit(StandardPlural start, StandardPlural end) { return(matrix.Get(start, end) != null); }
public StandardPlural Get(StandardPlural start, StandardPlural end) { StandardPlural?result = matrix.Get(start, end); return(result == null ? end : result.Value); }