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 #ifndef INTL_IMPL_H 16 #define INTL_IMPL_H 17 18 #include <string> 19 #include <vector> 20 #include "intl_ffi.h" 21 #include "ffi_remote_data.h" 22 #include "preferences_observer.h" 23 24 namespace OHOS { 25 namespace Global { 26 namespace I18n { 27 namespace Intl { 28 std::vector<std::string> ArrayStringToVectorString(CArrString arrString); 29 char *IMallocCString(const std::string &origin); 30 class NumberFormatImpl : public OHOS::FFI::FFIData { 31 DECL_TYPE(NumberFormatImpl, OHOS::FFI::FFIData) 32 public: 33 explicit NumberFormatImpl(int32_t *errCode); 34 NumberFormatImpl(char *locale, CNumberOptions options, int64_t flag, int32_t *errCode); 35 NumberFormatImpl(CArrString locale, CNumberOptions options, int64_t flag, int32_t *errCode); 36 char *Format(double number); 37 CNumberOptions ResolveOptions(); 38 39 private: 40 std::unique_ptr<OHOS::Global::I18n::NumberFormat> numberFmt_ = nullptr; 41 }; 42 43 class RelativeTimeFormatImpl : public OHOS::FFI::FFIData { 44 DECL_TYPE(RelativeTimeFormatImpl, OHOS::FFI::FFIData); 45 46 public: 47 explicit RelativeTimeFormatImpl(int32_t *errCode); 48 RelativeTimeFormatImpl(char *locale, CRelativeTimeFormatInputOptions options, int64_t flag, int32_t *errCode); 49 RelativeTimeFormatImpl( 50 CArrString locale, CRelativeTimeFormatInputOptions options, int64_t flag, int32_t *errCode); 51 char *Format(double number, char *unit); 52 CArrArrString FormatToParts(double number, char *unit); 53 CRelativeTimeFormatResolveOptions ResolveOptions(); 54 55 private: 56 std::unique_ptr<OHOS::Global::I18n::RelativeTimeFormat> relativeTimeFmt_ = nullptr; 57 }; 58 59 class PluralRulesImpl : public OHOS::FFI::FFIData { 60 DECL_TYPE(PluralRulesImpl, OHOS::FFI::FFIData); 61 62 public: 63 explicit PluralRulesImpl(int32_t *errCode); 64 PluralRulesImpl(char *locale, CPluralRulesOptions options, int64_t flag, int32_t *errCode); 65 PluralRulesImpl(CArrString locale, CPluralRulesOptions options, int64_t flag, int32_t *errCode); 66 char *Select(double n); 67 68 private: 69 std::unique_ptr<OHOS::Global::I18n::PluralRules> pluralRules_ = nullptr; 70 }; 71 72 class CollatorImpl : public OHOS::FFI::FFIData { 73 DECL_TYPE(CollatorImpl, OHOS::FFI::FFIData); 74 75 public: 76 explicit CollatorImpl(int32_t *errCode); 77 CollatorImpl(char *locale, CCollatorOptions options, int64_t flag, int32_t *errCode); 78 CollatorImpl(CArrString locale, CCollatorOptions options, int64_t flag, int32_t *errCode); 79 CCollatorOptions ResolveOptions(); 80 int32_t Compare(char *str1, char *str2); 81 82 private: 83 std::unique_ptr<OHOS::Global::I18n::Collator> collator_ = nullptr; 84 }; 85 86 class DateTimeFormatImpl : public OHOS::FFI::FFIData { 87 DECL_TYPE(DateTimeFormatImpl, OHOS::FFI::FFIData); 88 89 public: 90 explicit DateTimeFormatImpl(int32_t *errCode); 91 DateTimeFormatImpl(char *locale, CDateTimeOptions options, int64_t flag, int32_t *errCode); 92 DateTimeFormatImpl(CArrString locale, CDateTimeOptions options, int64_t flag, int32_t *errCode); 93 CDateTimeOptions ResolveOptions(); 94 char *Format(int64_t date); 95 char *FormatRange(int64_t startDate, int64_t endDate); 96 std::map<std::string, std::string> MapInsert(CDateTimeOptions options); 97 98 private: 99 std::unique_ptr<OHOS::Global::I18n::DateTimeFormat> dateFmt_ = nullptr; 100 }; 101 102 class LocaleImpl : public OHOS::FFI::FFIData { 103 DECL_TYPE(LocaleImpl, OHOS::FFI::FFIData); 104 105 public: 106 explicit LocaleImpl(int32_t *errCode); 107 LocaleImpl(char *locale, CLocaleOptions options, int64_t flag, int32_t *errCode); 108 char *ToString(); 109 char *Maximize(); 110 char *Minimize(); 111 112 char *GetLanguage(); 113 char *GetRegion(); 114 char *GetScript(); 115 char *GetBaseName(); 116 char *GetCaseFirst(); 117 char *GetCalendar(); 118 char *GetCollation(); 119 char *GetHourCycle(); 120 char *GetNumberingSystem(); 121 char *GetNumeric(); 122 123 private: 124 std::unique_ptr<OHOS::Global::I18n::LocaleInfo> locale_ = nullptr; 125 }; 126 127 } // namespace Intl 128 } // namespace I18n 129 } // namespace Global 130 } // namespace OHOS 131 #endif