• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #ifndef GLOBAL_I18N_STANDARD_PLURAL_RULES_H
16 #define GLOBAL_I18N_STANDARD_PLURAL_RULES_H
17 
18 #include <vector>
19 #include <string>
20 #include <map>
21 #include <set>
22 
23 #include "unicode/locid.h"
24 #include "unicode/plurrule.h"
25 #include "unicode/numberformatter.h"
26 
27 #include "locale_info.h"
28 
29 namespace OHOS {
30 namespace Global {
31 namespace I18n {
32 class PluralRules {
33 public:
34     PluralRules(std::vector<std::string> &localeTags, std::map<std::string, std::string> &options);
35     ~PluralRules();
36     std::string Select(double number);
37 
38 private:
39     std::string localeStr;
40     std::unique_ptr<LocaleInfo> localeInfo = nullptr;
41     icu::Locale locale;
42     icu::PluralRules *pluralRules = nullptr;
43     icu::number::LocalizedNumberFormatter numberFormatter;
44 
45     std::string localeMatcher;
46     std::string type;
47     int minInteger;
48     int minFraction;
49     int maxFraction;
50     int minSignificant;
51     int maxSignificant;
52 
53     std::set<std::string> GetValidLocales();
54     std::string ParseOption(std::map<std::string, std::string> &options, const std::string &key);
55     void ParseAllOptions(std::map<std::string, std::string> &options);
56     void InitPluralRules(std::vector<std::string> &localeTags, std::map<std::string, std::string> &options);
57     void InitNumberFormatter();
58 };
59 } // namespace I18n
60 } // namespace Global
61 } // namespace OHOS
62 #endif
63