/// <summary> /// Parses formatting expression, /// extracts and builds plural forms of a given word, /// delegates choise of the correct form to a Countable class instance. /// </summary> private string FormatCountable(string[] stringFormatParts, long arg) { var wordFormsString = stringFormatParts[stringFormatParts.Length - 1]; var wordForms = wordFormsString.Split('('); string one, two, five; if (wordForms.Length == 2) { // looks like "<stem>(<flexions>)" format is used var stem = wordForms[0]; var flectionsString = wordForms[1].Remove(wordForms[1].Length - 1, 1); var flexions = flectionsString.Split(','); one = stem + flexions[0]; two = flexions.Length > 1 ? stem + flexions[1] : one; five = flexions.Length > 2 ? stem + flexions[2] : two; } else { // looks like "<singular>, <plural 2>, <plural 5>" format is used wordForms = wordFormsString.Split(','); one = wordForms[0]; two = wordForms.Length > 1 ? wordForms[1] : one; five = wordForms.Length > 2 ? wordForms[2] : two; } // choose correct form for arg. var countable = new Countable(one, two, five); return(countable[Math.Abs(arg)]); }
/// <summary> /// Parses formatting expression, /// extracts and builds plural forms of a given word, /// delegates choise of the correct form to a Countable class instance. /// </summary> private string FormatCountable(string[] stringFormatParts, long arg) { var wordFormsString = stringFormatParts[stringFormatParts.Length - 1]; var wordForms = wordFormsString.Split('('); string one, two, five; if (wordForms.Length == 2) { // looks like "<stem>(<flexions>)" format is used var stem = wordForms[0]; var flectionsString = wordForms[1].Remove(wordForms[1].Length - 1, 1); var flexions = flectionsString.Split(','); one = stem + flexions[0]; two = flexions.Length > 1 ? stem + flexions[1] : one; five = flexions.Length > 2 ? stem + flexions[2] : two; } else { // looks like "<singular>, <plural 2>, <plural 5>" format is used wordForms = wordFormsString.Split(','); one = wordForms[0]; two = wordForms.Length > 1 ? wordForms[1] : one; five = wordForms.Length > 2 ? wordForms[2] : two; } // choose correct form for arg. var countable = new Countable(one, two, five); return countable[Math.Abs(arg)]; }