OLD | NEW |
(Empty) | |
| 1 /* |
| 2 ******************************************************************************* |
| 3 * Copyright (C) 2015, International Business Machines Corporation |
| 4 * and others. All Rights Reserved. |
| 5 ******************************************************************************* |
| 6 * standardplural.h |
| 7 * |
| 8 * created on: 2015dec14 |
| 9 * created by: Markus W. Scherer |
| 10 */ |
| 11 |
| 12 #ifndef __STANDARDPLURAL_H__ |
| 13 #define __STANDARDPLURAL_H__ |
| 14 |
| 15 #include "unicode/utypes.h" |
| 16 |
| 17 #if !UCONFIG_NO_FORMATTING |
| 18 |
| 19 U_NAMESPACE_BEGIN |
| 20 |
| 21 class UnicodeString; |
| 22 |
| 23 /** |
| 24 * Standard CLDR plural form/category constants. |
| 25 * See http://www.unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rul
es |
| 26 */ |
| 27 class U_I18N_API StandardPlural { |
| 28 public: |
| 29 enum Form { |
| 30 ZERO, |
| 31 ONE, |
| 32 TWO, |
| 33 FEW, |
| 34 MANY, |
| 35 OTHER, |
| 36 COUNT |
| 37 }; |
| 38 |
| 39 /** |
| 40 * @return the lowercase CLDR keyword string for the plural form |
| 41 */ |
| 42 static const char *getKeyword(Form p); |
| 43 |
| 44 /** |
| 45 * @param keyword for example "few" or "other" |
| 46 * @return the plural form corresponding to the keyword, or OTHER |
| 47 */ |
| 48 static Form orOtherFromString(const char *keyword) { |
| 49 return static_cast<Form>(indexOrOtherIndexFromString(keyword)); |
| 50 } |
| 51 |
| 52 /** |
| 53 * @param keyword for example "few" or "other" |
| 54 * @return the plural form corresponding to the keyword, or OTHER |
| 55 */ |
| 56 static Form orOtherFromString(const UnicodeString &keyword) { |
| 57 return static_cast<Form>(indexOrOtherIndexFromString(keyword)); |
| 58 } |
| 59 |
| 60 /** |
| 61 * Sets U_ILLEGAL_ARGUMENT_ERROR if the keyword is not a plural form. |
| 62 * |
| 63 * @param keyword for example "few" or "other" |
| 64 * @return the plural form corresponding to the keyword |
| 65 */ |
| 66 static Form fromString(const char *keyword, UErrorCode &errorCode) { |
| 67 return static_cast<Form>(indexFromString(keyword, errorCode)); |
| 68 } |
| 69 |
| 70 /** |
| 71 * Sets U_ILLEGAL_ARGUMENT_ERROR if the keyword is not a plural form. |
| 72 * |
| 73 * @param keyword for example "few" or "other" |
| 74 * @return the plural form corresponding to the keyword |
| 75 */ |
| 76 static Form fromString(const UnicodeString &keyword, UErrorCode &errorCode)
{ |
| 77 return static_cast<Form>(indexFromString(keyword, errorCode)); |
| 78 } |
| 79 |
| 80 /** |
| 81 * @param keyword for example "few" or "other" |
| 82 * @return the index of the plural form corresponding to the keyword, or a n
egative value |
| 83 */ |
| 84 static int32_t indexOrNegativeFromString(const char *keyword); |
| 85 |
| 86 /** |
| 87 * @param keyword for example "few" or "other" |
| 88 * @return the index of the plural form corresponding to the keyword, or a n
egative value |
| 89 */ |
| 90 static int32_t indexOrNegativeFromString(const UnicodeString &keyword); |
| 91 |
| 92 /** |
| 93 * @param keyword for example "few" or "other" |
| 94 * @return the index of the plural form corresponding to the keyword, or OTH
ER |
| 95 */ |
| 96 static int32_t indexOrOtherIndexFromString(const char *keyword) { |
| 97 int32_t i = indexOrNegativeFromString(keyword); |
| 98 return i >= 0 ? i : OTHER; |
| 99 } |
| 100 |
| 101 /** |
| 102 * @param keyword for example "few" or "other" |
| 103 * @return the index of the plural form corresponding to the keyword, or OTH
ER |
| 104 */ |
| 105 static int32_t indexOrOtherIndexFromString(const UnicodeString &keyword) { |
| 106 int32_t i = indexOrNegativeFromString(keyword); |
| 107 return i >= 0 ? i : OTHER; |
| 108 } |
| 109 |
| 110 /** |
| 111 * Sets U_ILLEGAL_ARGUMENT_ERROR if the keyword is not a plural form. |
| 112 * |
| 113 * @param keyword for example "few" or "other" |
| 114 * @return the index of the plural form corresponding to the keyword |
| 115 */ |
| 116 static int32_t indexFromString(const char *keyword, UErrorCode &errorCode); |
| 117 |
| 118 /** |
| 119 * Sets U_ILLEGAL_ARGUMENT_ERROR if the keyword is not a plural form. |
| 120 * |
| 121 * @param keyword for example "few" or "other" |
| 122 * @return the index of the plural form corresponding to the keyword |
| 123 */ |
| 124 static int32_t indexFromString(const UnicodeString &keyword, UErrorCode &err
orCode); |
| 125 }; |
| 126 |
| 127 U_NAMESPACE_END |
| 128 |
| 129 #endif // !UCONFIG_NO_FORMATTING |
| 130 #endif // __STANDARDPLURAL_H__ |
OLD | NEW |