1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PLURALFORMAT_H
17 #define PLURALFORMAT_H
18 
19 /**
20 * @addtogroup I18N
21 * @{
22 *
23 * @brief Provides APIs related to internationalization (i18n), with which you can
24 * format date, time, and numbers and obtain plural rules.
25 *
26 * @since 2.2
27 * @version 1.0
28 */
29 
30 /**
31 * @file plural_format.h
32 *
33 * @brief Provides functions that are used to obtain plural rules.
34 *
35 * @since 2.2
36 * @version 1.0
37 */
38 
39 #include "types.h"
40 #include "locale_info.h"
41 #include "plural_format_impl.h"
42 
43 namespace OHOS {
44 namespace I18N {
45 /**
46 * Obtains plural rules.
47 *
48 * @since 2.2
49 * @version 1.0
50 */
51 class PluralFormat {
52 public:
53     /**
54     * @brief A constructor used to create a <b>PluralFormat</b> object based on the specified locale.
55     *
56     * @param locale Indicates the specified locale.
57     * @param status Indicates the result of creating the <b>PluralFormat</b> object. I18nStatus::ISUCCESS
58     *               indicates that the operation is successful; I18nStatus::IERROR indicates that the
59     *               operation has failed.
60     * @since 2.2
61     * @version 1.0
62     */
63     PluralFormat(LocaleInfo &locale, I18nStatus &status);
64 
65     /**
66     * @brief A destructor used to delete the <b>PluralFormat</b> object.
67     *
68     * @since 2.2
69     * @version 1.0
70     */
71     virtual ~PluralFormat();
72 
73     /**
74     * @brief Obtains the index value of the plural rule for the specified number.
75     *
76     * @param num Indicates the number for which the plural rule is obtained.
77     * @param status Indicates the status of the process for obtaining the plural rule.
78     * @return Returns the index value of the plural rule; returns <b>-1</b> otherwise.
79     * @since 2.2
80     * @version 1.0
81     */
82     int GetPluralRuleIndex(int number, I18nStatus status);
83 
84     /**
85     * @brief Obtains the index value of the plural rule for the specified decimal number.
86     *
87     * @param num Indicates the decimal number for which the plural rule is obtained.
88     * @param status Indicates the status of the process for obtaining the plural rule.
89     * @return Returns the index value of the plural rule; returns <b>-1</b> otherwise.
90     * @version 1.0
91     */
92     int GetPluralRuleIndex(double number, I18nStatus status);
93 private:
94     bool Init();
95     PluralFormatImpl *impl = nullptr;
96     LocaleInfo mLocale;
97 };
98 } // namespace I18N
99 } // namespace OHOS
100 
101 #endif