19596a2c1Sopenharmony_ci/*
29596a2c1Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
39596a2c1Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
49596a2c1Sopenharmony_ci * you may not use this file except in compliance with the License.
59596a2c1Sopenharmony_ci * You may obtain a copy of the License at
69596a2c1Sopenharmony_ci *
79596a2c1Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
89596a2c1Sopenharmony_ci *
99596a2c1Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
109596a2c1Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
119596a2c1Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
129596a2c1Sopenharmony_ci * See the License for the specific language governing permissions and
139596a2c1Sopenharmony_ci * limitations under the License.
149596a2c1Sopenharmony_ci */
159596a2c1Sopenharmony_ci#ifndef OHOS_GLOBAL_I18N_NUMBER_FORMAT_H
169596a2c1Sopenharmony_ci#define OHOS_GLOBAL_I18N_NUMBER_FORMAT_H
179596a2c1Sopenharmony_ci
189596a2c1Sopenharmony_ci#include <map>
199596a2c1Sopenharmony_ci#include <set>
209596a2c1Sopenharmony_ci#include <unordered_map>
219596a2c1Sopenharmony_ci#include <vector>
229596a2c1Sopenharmony_ci#include "unicode/numberformatter.h"
239596a2c1Sopenharmony_ci#include "unicode/locid.h"
249596a2c1Sopenharmony_ci#include "unicode/numfmt.h"
259596a2c1Sopenharmony_ci#include "unicode/unum.h"
269596a2c1Sopenharmony_ci#include "unicode/decimfmt.h"
279596a2c1Sopenharmony_ci#include "unicode/localebuilder.h"
289596a2c1Sopenharmony_ci#include "unicode/numsys.h"
299596a2c1Sopenharmony_ci#include "unicode/measfmt.h"
309596a2c1Sopenharmony_ci#include "unicode/measunit.h"
319596a2c1Sopenharmony_ci#include "unicode/measure.h"
329596a2c1Sopenharmony_ci#include "unicode/currunit.h"
339596a2c1Sopenharmony_ci#include "unicode/fmtable.h"
349596a2c1Sopenharmony_ci#include "unicode/ures.h"
359596a2c1Sopenharmony_ci#include "unicode/ulocdata.h"
369596a2c1Sopenharmony_ci#include "number_utils.h"
379596a2c1Sopenharmony_ci#include "number_utypes.h"
389596a2c1Sopenharmony_ci#include "locale_info.h"
399596a2c1Sopenharmony_ci#include "measure_data.h"
409596a2c1Sopenharmony_ci#include "relative_time_format.h"
419596a2c1Sopenharmony_ci
429596a2c1Sopenharmony_cinamespace OHOS {
439596a2c1Sopenharmony_cinamespace Global {
449596a2c1Sopenharmony_cinamespace I18n {
459596a2c1Sopenharmony_ciclass NumberFormat {
469596a2c1Sopenharmony_cipublic:
479596a2c1Sopenharmony_ci    NumberFormat(const std::vector<std::string> &localeTag, std::map<std::string, std::string> &configs);
489596a2c1Sopenharmony_ci    virtual ~NumberFormat();
499596a2c1Sopenharmony_ci    std::string Format(double number);
509596a2c1Sopenharmony_ci    void GetResolvedOptions(std::map<std::string, std::string> &map);
519596a2c1Sopenharmony_ci    std::string GetCurrency() const;
529596a2c1Sopenharmony_ci    std::string GetCurrencySign() const;
539596a2c1Sopenharmony_ci    std::string GetStyle() const;
549596a2c1Sopenharmony_ci    std::string GetNumberingSystem() const;
559596a2c1Sopenharmony_ci    std::string GetUseGrouping() const;
569596a2c1Sopenharmony_ci    std::string GetMinimumIntegerDigits() const;
579596a2c1Sopenharmony_ci    std::string GetMinimumFractionDigits() const;
589596a2c1Sopenharmony_ci    std::string GetMaximumFractionDigits() const;
599596a2c1Sopenharmony_ci    std::string GetMinimumSignificantDigits() const;
609596a2c1Sopenharmony_ci    std::string GetMaximumSignificantDigits() const;
619596a2c1Sopenharmony_ci    std::string GetLocaleMatcher() const;
629596a2c1Sopenharmony_ci
639596a2c1Sopenharmony_ciprivate:
649596a2c1Sopenharmony_ci    icu::Locale locale;
659596a2c1Sopenharmony_ci    std::string currency;
669596a2c1Sopenharmony_ci    std::string currencySign = "standard";
679596a2c1Sopenharmony_ci    std::string currencyDisplayString;
689596a2c1Sopenharmony_ci    std::string unit;
699596a2c1Sopenharmony_ci    std::string unitDisplayString;
709596a2c1Sopenharmony_ci    std::string styleString;
719596a2c1Sopenharmony_ci    std::string numberingSystem;
729596a2c1Sopenharmony_ci    std::string useGrouping;
739596a2c1Sopenharmony_ci    std::string notationString;
749596a2c1Sopenharmony_ci    std::string signDisplayString = "auto";
759596a2c1Sopenharmony_ci    std::string compactDisplay;
769596a2c1Sopenharmony_ci    std::string minimumIntegerDigits;
779596a2c1Sopenharmony_ci    std::string minimumFractionDigits;
789596a2c1Sopenharmony_ci    std::string maximumFractionDigits;
799596a2c1Sopenharmony_ci    std::string minimumSignificantDigits;
809596a2c1Sopenharmony_ci    std::string maximumSignificantDigits;
819596a2c1Sopenharmony_ci    std::string localeBaseName;
829596a2c1Sopenharmony_ci    std::string localeMatcher;
839596a2c1Sopenharmony_ci    std::string unitUsage;
849596a2c1Sopenharmony_ci    std::string unitType;
859596a2c1Sopenharmony_ci    std::string unitMeasSys;
869596a2c1Sopenharmony_ci    bool createSuccess = false;
879596a2c1Sopenharmony_ci    bool isSetFraction = false;
889596a2c1Sopenharmony_ci    std::unique_ptr<LocaleInfo> localeInfo = nullptr;
899596a2c1Sopenharmony_ci    std::unique_ptr<RelativeTimeFormat> relativeTimeFormat = nullptr;
909596a2c1Sopenharmony_ci    icu::number::LocalizedNumberFormatter numberFormat;
919596a2c1Sopenharmony_ci    icu::number::Notation notation = icu::number::Notation::simple();
929596a2c1Sopenharmony_ci    UNumberUnitWidth unitDisplay = UNumberUnitWidth::UNUM_UNIT_WIDTH_SHORT;
939596a2c1Sopenharmony_ci    UNumberUnitWidth currencyDisplay = UNumberUnitWidth::UNUM_UNIT_WIDTH_SHORT;
949596a2c1Sopenharmony_ci    UNumberSignDisplay signDisplay = UNumberSignDisplay::UNUM_SIGN_AUTO;
959596a2c1Sopenharmony_ci    static const int MAX_UNIT_NUM = 500;
969596a2c1Sopenharmony_ci    static const int DEFAULT_FRACTION_DIGITS = 3;
979596a2c1Sopenharmony_ci    static const char *DEVICE_TYPE_NAME;
989596a2c1Sopenharmony_ci    static const int BUFFER_LEN = 10;
999596a2c1Sopenharmony_ci    static const int CURRENCY_LEN = 3;
1009596a2c1Sopenharmony_ci    static std::unordered_map<std::string, std::string> numToCurrency;
1019596a2c1Sopenharmony_ci    icu::MeasureUnit unitArray[MAX_UNIT_NUM];
1029596a2c1Sopenharmony_ci    static bool icuInitialized;
1039596a2c1Sopenharmony_ci    static bool Init();
1049596a2c1Sopenharmony_ci    static std::unordered_map<std::string, UNumberUnitWidth> unitStyle;
1059596a2c1Sopenharmony_ci    static std::unordered_map<std::string, UNumberUnitWidth> currencyStyle;
1069596a2c1Sopenharmony_ci    static std::unordered_map<std::string, UNumberSignDisplay> signAutoStyle;
1079596a2c1Sopenharmony_ci    static std::unordered_map<std::string, UNumberSignDisplay> signAccountingStyle;
1089596a2c1Sopenharmony_ci    static std::unordered_map<UMeasurementSystem, std::string> measurementSystem;
1099596a2c1Sopenharmony_ci    static std::unordered_map<std::string, UNumberUnitWidth> defaultUnitStyle;
1109596a2c1Sopenharmony_ci    static std::unordered_map<std::string, UNumberUnitWidth> defaultCurrencyStyle;
1119596a2c1Sopenharmony_ci    static std::map<std::string, std::string> RelativeTimeFormatConfigs;
1129596a2c1Sopenharmony_ci    static bool ReadISO4217Ddatas();
1139596a2c1Sopenharmony_ci    std::string GetCurrencyFromConfig(const std::string& currency);
1149596a2c1Sopenharmony_ci    void CreateRelativeTimeFormat(const std::string& locale);
1159596a2c1Sopenharmony_ci    void ParseConfigs(std::map<std::string, std::string> &configs);
1169596a2c1Sopenharmony_ci    void ParseDigitsConfigs(std::map<std::string, std::string> &configs);
1179596a2c1Sopenharmony_ci    void GetDigitsResolvedOptions(std::map<std::string, std::string> &map);
1189596a2c1Sopenharmony_ci    void InitProperties();
1199596a2c1Sopenharmony_ci    void InitDigitsProperties();
1209596a2c1Sopenharmony_ci    void SetUnit(std::string &preferredUnit);
1219596a2c1Sopenharmony_ci    void SetDefaultStyle();
1229596a2c1Sopenharmony_ci    void SetPrecisionWithByte(double number, const std::string& finalUnit);
1239596a2c1Sopenharmony_ci};
1249596a2c1Sopenharmony_ci} // namespace I18n
1259596a2c1Sopenharmony_ci} // namespace Global
1269596a2c1Sopenharmony_ci} // namespace OHOS
1279596a2c1Sopenharmony_ci#endif