1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2015, International Business Machines Corporation
6 * and others. All Rights Reserved.
7 *******************************************************************************
10 * created on: 2015dec14
11 * created by: Markus W. Scherer
14 #ifndef __STANDARDPLURAL_H__
15 #define __STANDARDPLURAL_H__
17 #include "unicode/utypes.h"
19 #if !UCONFIG_NO_FORMATTING
26 * Standard CLDR plural form/category constants.
27 * See http://www.unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules
29 class U_I18N_API StandardPlural {
42 * @return the lowercase CLDR keyword string for the plural form
44 static const char *getKeyword(Form p);
47 * @param keyword for example "few" or "other"
48 * @return the plural form corresponding to the keyword, or OTHER
50 static Form orOtherFromString(const char *keyword) {
51 return static_cast<Form>(indexOrOtherIndexFromString(keyword));
55 * @param keyword for example "few" or "other"
56 * @return the plural form corresponding to the keyword, or OTHER
58 static Form orOtherFromString(const UnicodeString &keyword) {
59 return static_cast<Form>(indexOrOtherIndexFromString(keyword));
63 * Sets U_ILLEGAL_ARGUMENT_ERROR if the keyword is not a plural form.
65 * @param keyword for example "few" or "other"
66 * @return the plural form corresponding to the keyword
68 static Form fromString(const char *keyword, UErrorCode &errorCode) {
69 return static_cast<Form>(indexFromString(keyword, errorCode));
73 * Sets U_ILLEGAL_ARGUMENT_ERROR if the keyword is not a plural form.
75 * @param keyword for example "few" or "other"
76 * @return the plural form corresponding to the keyword
78 static Form fromString(const UnicodeString &keyword, UErrorCode &errorCode) {
79 return static_cast<Form>(indexFromString(keyword, errorCode));
83 * @param keyword for example "few" or "other"
84 * @return the index of the plural form corresponding to the keyword, or a negative value
86 static int32_t indexOrNegativeFromString(const char *keyword);
89 * @param keyword for example "few" or "other"
90 * @return the index of the plural form corresponding to the keyword, or a negative value
92 static int32_t indexOrNegativeFromString(const UnicodeString &keyword);
95 * @param keyword for example "few" or "other"
96 * @return the index of the plural form corresponding to the keyword, or OTHER
98 static int32_t indexOrOtherIndexFromString(const char *keyword) {
99 int32_t i = indexOrNegativeFromString(keyword);
100 return i >= 0 ? i : OTHER;
104 * @param keyword for example "few" or "other"
105 * @return the index of the plural form corresponding to the keyword, or OTHER
107 static int32_t indexOrOtherIndexFromString(const UnicodeString &keyword) {
108 int32_t i = indexOrNegativeFromString(keyword);
109 return i >= 0 ? i : OTHER;
113 * Sets U_ILLEGAL_ARGUMENT_ERROR if the keyword is not a plural form.
115 * @param keyword for example "few" or "other"
116 * @return the index of the plural form corresponding to the keyword
118 static int32_t indexFromString(const char *keyword, UErrorCode &errorCode);
121 * Sets U_ILLEGAL_ARGUMENT_ERROR if the keyword is not a plural form.
123 * @param keyword for example "few" or "other"
124 * @return the index of the plural form corresponding to the keyword
126 static int32_t indexFromString(const UnicodeString &keyword, UErrorCode &errorCode);
131 #endif // !UCONFIG_NO_FORMATTING
132 #endif // __STANDARDPLURAL_H__