1 /* 2 * Copyright (C) 2023 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 OPERATOR_NAME_UTILS_H 17 #define OPERATOR_NAME_UTILS_H 18 19 #include <mutex> 20 21 #include "cJSON.h" 22 #include "iosfwd" 23 #include "string" 24 25 namespace OHOS { 26 namespace Telephony { 27 class OperatorNameUtils { 28 struct OperatorNameCust { 29 std::vector<std::string> mccMnc = {}; 30 std::string zhCN = ""; 31 std::string enUS = ""; 32 std::string zhTW = ""; 33 std::string zhHK = ""; 34 std::string zhHans = ""; 35 std::string zhHant = ""; 36 }; 37 38 public: 39 static OperatorNameUtils &GetInstance(); 40 void Init(); 41 bool IsInit(); 42 std::string GetCustomName(const std::string &numeric); 43 44 private: 45 OperatorNameUtils() = default; 46 ~OperatorNameUtils() = default; 47 void ParserOperatorNames(std::vector<OperatorNameCust> &vec, cJSON *itemRoots); 48 int32_t LoaderJsonFile(char *&content, const char *path) const; 49 int32_t ParserOperatorNameCustJson(std::vector<OperatorNameCust> &vec); 50 int32_t CloseFile(FILE *f) const; 51 std::string GetNameByLocale(OperatorNameCust &value); 52 std::string ParseString(cJSON *value); 53 54 private: 55 static OperatorNameUtils operatorNameUtils_; 56 bool isInit_ = false; 57 std::vector<OperatorNameCust> nameArray_ = {}; 58 std::mutex mutex_; 59 }; 60 } // namespace Telephony 61 } // namespace OHOS 62 #endif 63