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 NUMBERFORMAT_IMPL_H 17 #define NUMBERFORMAT_IMPL_H 18 19 #include "types.h" 20 #include "securec.h" 21 #include "locale_info.h" 22 #include "data_resource.h" 23 #include "number_data.h" 24 25 namespace OHOS { 26 namespace I18N { 27 class NumberFormatImpl { 28 public: 29 NumberFormatImpl(LocaleInfo &locale, int &status); 30 virtual ~NumberFormatImpl(); 31 std::string Format(double num, NumberFormatType type, int &status) const; 32 std::string Format(int num, int &status) const; 33 std::string FormatNoGroup(double num, NumberFormatType type, int &status) const; 34 std::string FormatNoGroup(int num, int &status) const; 35 bool Init(const DataResource &resource); 36 bool SetMaxDecimalLength(int length); 37 bool SetMinDecimalLength(int length); 38 private: 39 NumberData *defaultData = nullptr; 40 LocaleInfo mLocale; 41 int maxDecimalLength = -1; 42 int minDecimalLength = -1; 43 void CheckStatus(const errno_t rc, int &status) const; 44 int DelMoreZero(const StyleData &style, int decLen, int lastLen, bool hasDec, char *&result) const; 45 std::string InnerFormat(double num, bool hasDec, bool isShowGroup, bool isPercent, int &status) const; 46 std::string ConvertSignAndNum(const char *content, int len, NumberData *data, StyleData &style) const; 47 int ConvertNum(std::string &strContent, char currentChar, const NumberData *data, int index, int off) const; 48 int DelZero(char *target, int len, int delNum, bool onlyZero) const; 49 void AddGroup(char *targetAndSource[], const int len[], const char *decimal, bool hasDec, int decLen) const; 50 int CountGroupNum(int intLength, bool isTwoGrouped) const; 51 char *FillMinDecimal(const char *target, int len, int addSize, bool isDec) const; 52 bool DealWithPercent(char *buff, char *&result, int &status, StyleData &style, int &lastLen) const; 53 static constexpr int NUMBER_MAX = 50; 54 static constexpr int NO_SET = -1; 55 }; 56 } // namespace I18N 57 } // namespace OHOS 58 #endif 59