1 /* 2 * Copyright (c) 2021-2022 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 OHOS_GLOBAL_I18N_PHONE_NUMBER_FORMAT_H 16 #define OHOS_GLOBAL_I18N_PHONE_NUMBER_FORMAT_H 17 18 #include <map> 19 #include <string> 20 21 #include "memory" 22 #include "cpp/src/phonenumbers/phonenumberutil.h" 23 24 namespace OHOS { 25 namespace Global { 26 namespace I18n { 27 using i18n::phonenumbers::PhoneNumberUtil; 28 using ExposeLocationName = void (*)(const char*, const char*, char*); 29 30 class PhoneNumberFormat { 31 public: 32 PhoneNumberFormat(const std::string &countryTag, const std::map<std::string, std::string> &options); 33 virtual ~PhoneNumberFormat(); 34 bool isValidPhoneNumber(const std::string &number) const; 35 std::string format(const std::string &number) const; 36 static std::unique_ptr<PhoneNumberFormat> CreateInstance(const std::string &countryTag, 37 const std::map<std::string, std::string> &options); 38 std::string getLocationName(const std::string &number, const std::string &locale); 39 40 private: 41 PhoneNumberUtil* GetPhoneNumberUtil(); 42 PhoneNumberUtil *util; 43 std::string country; 44 PhoneNumberUtil::PhoneNumberFormat phoneNumberFormat; 45 void* g_dynamicHandler = nullptr; 46 ExposeLocationName g_func = nullptr; 47 }; 48 } // namespace I18n 49 } // namespace Global 50 } // namespace OHOS 51 #endif 52