2 *******************************************************************************
3 * Copyright (C) 2015, International Business Machines Corporation
4 * and others. All Rights Reserved.
5 *******************************************************************************
8 * created on: 2015dec14
9 * created by: Markus W. Scherer
12 #ifndef __STANDARDPLURAL_H__
13 #define __STANDARDPLURAL_H__
15 #include "unicode/utypes.h"
17 #if !UCONFIG_NO_FORMATTING
24 * Standard CLDR plural form/category constants.
25 * See http://www.unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules
27 class U_I18N_API StandardPlural
{
40 * @return the lowercase CLDR keyword string for the plural form
42 static const char *getKeyword(Form p
);
45 * @param keyword for example "few" or "other"
46 * @return the plural form corresponding to the keyword, or OTHER
48 static Form
orOtherFromString(const char *keyword
) {
49 return static_cast<Form
>(indexOrOtherIndexFromString(keyword
));
53 * @param keyword for example "few" or "other"
54 * @return the plural form corresponding to the keyword, or OTHER
56 static Form
orOtherFromString(const UnicodeString
&keyword
) {
57 return static_cast<Form
>(indexOrOtherIndexFromString(keyword
));
61 * Sets U_ILLEGAL_ARGUMENT_ERROR if the keyword is not a plural form.
63 * @param keyword for example "few" or "other"
64 * @return the plural form corresponding to the keyword
66 static Form
fromString(const char *keyword
, UErrorCode
&errorCode
) {
67 return static_cast<Form
>(indexFromString(keyword
, errorCode
));
71 * Sets U_ILLEGAL_ARGUMENT_ERROR if the keyword is not a plural form.
73 * @param keyword for example "few" or "other"
74 * @return the plural form corresponding to the keyword
76 static Form
fromString(const UnicodeString
&keyword
, UErrorCode
&errorCode
) {
77 return static_cast<Form
>(indexFromString(keyword
, errorCode
));
81 * @param keyword for example "few" or "other"
82 * @return the index of the plural form corresponding to the keyword, or a negative value
84 static int32_t indexOrNegativeFromString(const char *keyword
);
87 * @param keyword for example "few" or "other"
88 * @return the index of the plural form corresponding to the keyword, or a negative value
90 static int32_t indexOrNegativeFromString(const UnicodeString
&keyword
);
93 * @param keyword for example "few" or "other"
94 * @return the index of the plural form corresponding to the keyword, or OTHER
96 static int32_t indexOrOtherIndexFromString(const char *keyword
) {
97 int32_t i
= indexOrNegativeFromString(keyword
);
98 return i
>= 0 ? i
: OTHER
;
102 * @param keyword for example "few" or "other"
103 * @return the index of the plural form corresponding to the keyword, or OTHER
105 static int32_t indexOrOtherIndexFromString(const UnicodeString
&keyword
) {
106 int32_t i
= indexOrNegativeFromString(keyword
);
107 return i
>= 0 ? i
: OTHER
;
111 * Sets U_ILLEGAL_ARGUMENT_ERROR if the keyword is not a plural form.
113 * @param keyword for example "few" or "other"
114 * @return the index of the plural form corresponding to the keyword
116 static int32_t indexFromString(const char *keyword
, UErrorCode
&errorCode
);
119 * Sets U_ILLEGAL_ARGUMENT_ERROR if the keyword is not a plural form.
121 * @param keyword for example "few" or "other"
122 * @return the index of the plural form corresponding to the keyword
124 static int32_t indexFromString(const UnicodeString
&keyword
, UErrorCode
&errorCode
);
129 #endif // !UCONFIG_NO_FORMATTING
130 #endif // __STANDARDPLURAL_H__