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