• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef OHOS_GLOBAL_I18N_NUMBER_FORMAT_H
16 #define OHOS_GLOBAL_I18N_NUMBER_FORMAT_H
17 
18 #include <map>
19 #include <set>
20 #include <unordered_map>
21 #include <vector>
22 #include "unicode/numberformatter.h"
23 #include "unicode/locid.h"
24 #include "unicode/numfmt.h"
25 #include "unicode/unum.h"
26 #include "unicode/decimfmt.h"
27 #include "unicode/localebuilder.h"
28 #include "unicode/numsys.h"
29 #include "unicode/measfmt.h"
30 #include "unicode/measunit.h"
31 #include "unicode/measure.h"
32 #include "unicode/currunit.h"
33 #include "unicode/fmtable.h"
34 #include "unicode/ures.h"
35 #include "unicode/ulocdata.h"
36 #include "number_utils.h"
37 #include "number_utypes.h"
38 #include "locale_info.h"
39 #include "measure_data.h"
40 
41 namespace OHOS {
42 namespace Global {
43 namespace I18n {
44 class NumberFormat {
45 public:
46     NumberFormat(const std::vector<std::string> &localeTag, std::map<std::string, std::string> &configs);
47     virtual ~NumberFormat();
48     std::string Format(double number);
49     void GetResolvedOptions(std::map<std::string, std::string> &map);
50     std::string GetCurrency() const;
51     std::string GetCurrencySign() const;
52     std::string GetStyle() const;
53     std::string GetNumberingSystem() const;
54     std::string GetUseGrouping() const;
55     std::string GetMinimumIntegerDigits() const;
56     std::string GetMinimumFractionDigits() const;
57     std::string GetMaximumFractionDigits() const;
58     std::string GetMinimumSignificantDigits() const;
59     std::string GetMaximumSignificantDigits() const;
60     std::string GetLocaleMatcher() const;
61 
62 private:
63     icu::Locale locale;
64     std::string currency;
65     std::string currencySign;
66     std::string currencyDisplayString;
67     std::string unit;
68     std::string unitDisplayString;
69     std::string styleString;
70     std::string numberingSystem;
71     std::string useGrouping;
72     std::string notationString;
73     std::string signDisplayString;
74     std::string compactDisplay;
75     std::string minimumIntegerDigits;
76     std::string minimumFractionDigits;
77     std::string maximumFractionDigits;
78     std::string minimumSignificantDigits;
79     std::string maximumSignificantDigits;
80     std::string localeBaseName;
81     std::string localeMatcher;
82     std::string unitUsage;
83     std::string unitType;
84     std::string unitMeasSys;
85     LocaleInfo *localeInfo = nullptr;
86     icu::number::LocalizedNumberFormatter numberFormat;
87     icu::number::Notation notation = icu::number::Notation::simple();
88     UNumberUnitWidth unitDisplay = UNumberUnitWidth::UNUM_UNIT_WIDTH_SHORT;
89     UNumberUnitWidth currencyDisplay = UNumberUnitWidth::UNUM_UNIT_WIDTH_SHORT;
90     UNumberSignDisplay signDisplay = UNumberSignDisplay::UNUM_SIGN_AUTO;
91     static const int MAX_UNIT_NUM = 500;
92     static const int DEFAULT_FRACTION_DIGITS = 3;
93     icu::MeasureUnit unitArray[MAX_UNIT_NUM];
94     static bool icuInitialized;
95     static bool Init();
96     static std::unordered_map<std::string, UNumberUnitWidth> unitStyle;
97     static std::unordered_map<std::string, UNumberUnitWidth> currencyStyle;
98     static std::unordered_map<std::string, UNumberSignDisplay> signAutoStyle;
99     static std::unordered_map<std::string, UNumberSignDisplay> signAccountingStyle;
100     static std::unordered_map<UMeasurementSystem, std::string> measurementSystem;
101     void ParseConfigs(std::map<std::string, std::string> &configs);
102     void ParseDigitsConfigs(std::map<std::string, std::string> &configs);
103     void GetDigitsResolvedOptions(std::map<std::string, std::string> &map);
104     void InitProperties();
105     void InitDigitsProperties();
106 };
107 } // namespace I18n
108 } // namespace Global
109 } // namespace OHOS
110 #endif