• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 OHOS_GLOBAL_I18N_STYLED_NUMBER_FORMAT_H
17 #define OHOS_GLOBAL_I18N_STYLED_NUMBER_FORMAT_H
18 
19 #include <vector>
20 
21 #include "number_format.h"
22 #include "simple_number_format.h"
23 #include "unicode/numberformatter.h"
24 
25 namespace OHOS {
26 namespace Global {
27 namespace I18n {
28 class StyledNumberFormat {
29 public:
30     struct NumberPart {
31         std::string part_name;
32         size_t start;
33         size_t length;
34     };
35 
36     StyledNumberFormat(bool isNumberFormat, std::shared_ptr<NumberFormat> numberFormat,
37         std::shared_ptr<SimpleNumberFormat> simpleNumberFormat);
38     std::string Format(double number);
39     std::vector<StyledNumberFormat::NumberPart> ParseToParts(double number);
40 
41 private:
42     std::vector<StyledNumberFormat::NumberPart> ParseToParts(icu::number::FormattedNumber &formattedValue);
43     std::vector<StyledNumberFormat::NumberPart> ParseToParts(icu::FormattedRelativeDateTime &formattedValue);
44     void HandlePart(const std::string& part, std::unordered_map<std::string, size_t> &index,
45         std::vector<StyledNumberFormat::NumberPart> &result);
46 
47     bool isNumberFormat;
48     std::shared_ptr<NumberFormat> numberFormat;
49     std::shared_ptr<SimpleNumberFormat> simpleNumberFormat;
50 };
51 } // namespace I18n
52 } // namespace Global
53 } // namespace OHOS
54 #endif