diff --git a/src/strings.cpp b/src/strings.cpp index 32f2a297cf..0608fc12e1 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -400,74 +400,75 @@ static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, Money n return buff; } -static int DeterminePluralForm(int64 cnt) +static int DeterminePluralForm(int64 count) { - uint64 n = cnt; /* The absolute value determines plurality */ - if (cnt < 0) n = -cnt; + uint64 n = abs(count); switch (_langpack->plural_form) { - /* Two forms, singular used for one only - * Used in: - * Danish, Dutch, English, German, Norwegian, Swedish, Estonian, Finnish, - * Greek, Hebrew, Italian, Portuguese, Spanish, Esperanto */ - case 0: - default: - return n != 1; + default: + NOT_REACHED(); - /* Only one form - * Used in: - * Hungarian, Japanese, Korean, Turkish */ - case 1: - return 0; + /* Two forms, singular used for one only + * Used in: + * Danish, Dutch, English, German, Norwegian, Swedish, Estonian, Finnish, + * Greek, Hebrew, Italian, Portuguese, Spanish, Esperanto */ + case 0: + return n != 1; - /* Two forms, singular used for zero and one - * Used in: - * French, Brazilian Portuguese */ - case 2: - return n > 1; + /* Only one form + * Used in: + * Hungarian, Japanese, Korean, Turkish */ + case 1: + return 0; - /* Three forms, special case for zero - * Used in: - * Latvian */ - case 3: - return n % 10 == 1 && n % 100 != 11 ? 0 : n != 0 ? 1 : 2; + /* Two forms, singular used for zero and one + * Used in: + * French, Brazilian Portuguese */ + case 2: + return n > 1; - /* Three forms, special case for one and two - * Used in: - * Gaelige (Irish) */ - case 4: - return n == 1 ? 0 : n == 2 ? 1 : 2; + /* Three forms, special case for zero + * Used in: + * Latvian */ + case 3: + return n % 10 == 1 && n % 100 != 11 ? 0 : n != 0 ? 1 : 2; - /* Three forms, special case for numbers ending in 1[2-9] - * Used in: - * Lithuanian */ - case 5: - return n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2; + /* Three forms, special case for one and two + * Used in: + * Gaelige (Irish) */ + case 4: + return n == 1 ? 0 : n == 2 ? 1 : 2; - /* Three forms, special cases for numbers ending in 1 and 2, 3, 4, except those ending in 1[1-4] - * Used in: - * Croatian, Czech, Russian, Slovak, Ukrainian */ - case 6: - return n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2; + /* Three forms, special case for numbers ending in 1[2-9] + * Used in: + * Lithuanian */ + case 5: + return n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2; - /* Three forms, special case for one and some numbers ending in 2, 3, or 4 - * Used in: - * Polish */ - case 7: - return n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2; + /* Three forms, special cases for numbers ending in 1 and 2, 3, 4, except those ending in 1[1-4] + * Used in: + * Croatian, Czech, Russian, Slovak, Ukrainian */ + case 6: + return n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2; - /* Four forms, special case for one and all numbers ending in 02, 03, or 04 - * Used in: - * Slovenian */ - case 8: - return n % 100 == 1 ? 0 : n % 100 == 2 ? 1 : n % 100 == 3 || n % 100 == 4 ? 2 : 3; + /* Three forms, special case for one and some numbers ending in 2, 3, or 4 + * Used in: + * Polish */ + case 7: + return n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2; - /* Two forms; singular used for everything ending in 1 but not in 11. - * Used in: - * Icelandic */ - case 9: - return n % 10 == 1 && n % 100 != 11 ? 0 : 1; + /* Four forms, special case for one and all numbers ending in 02, 03, or 04 + * Used in: + * Slovenian */ + case 8: + return n % 100 == 1 ? 0 : n % 100 == 2 ? 1 : n % 100 == 3 || n % 100 == 4 ? 2 : 3; + + /* Two forms; singular used for everything ending in 1 but not in 11. + * Used in: + * Icelandic */ + case 9: + return n % 10 == 1 && n % 100 != 11 ? 0 : 1; } }