1 /* 2 * Copyright (c) 2025 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_VARIABLE_CONVERTER_H 17 #define OHOS_GLOBAL_I18N_VARIABLE_CONVERTER_H 18 19 #include <string> 20 #include <vector> 21 #include "ani.h" 22 23 namespace OHOS { 24 namespace Global { 25 namespace I18n { 26 class VariableConverter { 27 public: 28 static std::string AniStrToString(ani_env *env, ani_ref aniStr); 29 static ani_string StringToAniStr(ani_env *env, const std::string &str); 30 static void SetBooleanMember(ani_env *env, ani_object obj, const std::string &name, const std::string &value); 31 static bool GetBooleanMember(ani_env *env, ani_object options, const std::string &name, bool& value); 32 static void SetNumberMember(ani_env *env, ani_object obj, const std::string &name, const ani_int value); 33 static void SetNumberMember(ani_env *env, ani_object obj, const std::string &name, const std::string &value); 34 static bool GetNumberMember(ani_env *env, ani_object options, const std::string &name, int& value); 35 static void SetStringMember(ani_env *env, ani_object obj, const std::string &name, const std::string &value); 36 static bool GetStringMember(ani_env *env, ani_object options, const std::string &name, std::string &value); 37 static ani_object CreateArray(ani_env *env, const std::vector<std::string> &strs); 38 static bool ParseStringArray(ani_env *env, ani_object obj, std::vector<std::string> &strs); 39 static ani_enum_item GetEnumItemByIndex(ani_env* env, const char* enumClassName, const int index); 40 static ani_double GetDateValue(ani_env *env, ani_object date, const std::string &method); 41 static std::vector<std::string> GetLocaleTags(ani_env *env, ani_object locale); 42 template<typename T> 43 static ani_object CreateAniObject(ani_env* env, const char* className, T* ptr); 44 }; 45 } // namespace I18n 46 } // namespace Global 47 } // namespace OHOS 48 #endif 49