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 #ifndef OHOS_GLOBAL_I18N_UTILS_H 16 #define OHOS_GLOBAL_I18N_UTILS_H 17 18 #include <filesystem> 19 #include <regex> 20 #include <string> 21 #include <vector> 22 #include <unordered_set> 23 #include <unicode/locid.h> 24 #include "set" 25 #include "i18n_types.h" 26 27 namespace OHOS { 28 namespace Global { 29 namespace I18n { 30 static std::set<std::string> availableIDs; 31 32 void Split(const std::string &src, const std::string &sep, std::vector<std::string> &dest); 33 void Split(const std::string& src, const std::string& sep, std::unordered_set<std::string>& dest); 34 void Merge(const std::vector<std::string>& src, const std::string& sep, std::string& dest); 35 std::string ReadSystemParameter(const char *paramKey, const int paramLength); 36 int32_t ConvertString2Int(const std::string &numberStr, int32_t& status, int base = 10); 37 double ConvertString2Double(const std::string &numberStr, int32_t& status); 38 bool IsValidLocaleTag(icu::Locale &locale); 39 void GetAllValidLocalesTag(std::unordered_set<std::string>& allValidLocalesLanguageTag); 40 std::string GetAbsoluteFilePath(const std::string &filePath); 41 std::string StrReplaceAll(const std::string& str, 42 const std::string& target, const std::string& replace); 43 std::string GetISO3Language(const std::string& language); 44 std::string GetISO3Country(const std::string& country); 45 std::string trim(std::string &s); 46 bool FileExist(const std::string& path); 47 bool FileCopy(const std::string& srcPath, const std::string& dstPath); 48 bool IsLegalPath(const std::string& path); 49 bool IsDirExist(const char *path); 50 void ClearDir(const std::filesystem::path& dirPath); 51 bool GetPseudoLocalizationEnforce(); 52 std::string PseudoLocalizationProcessor(const std::string &input); 53 std::string PseudoLocalizationProcessor(const std::string &input, bool ifEnforce); 54 bool CheckSystemPermission(); 55 std::set<std::string> GetTimeZoneAvailableIDs(I18nErrorCode &errorCode); 56 bool RegexSearchNoExcept(const std::string& str, std::smatch& match, const std::regex& regex); 57 std::string LocaleEncode(const std::string& locale); 58 bool Eq(double a, double b); 59 bool Geq(double a, double b); 60 bool Leq(double a, double b); 61 std::string StrToHex(const std::string& text, size_t num); 62 std::string HexToStr(const std::string& hex); 63 } // namespace I18n 64 } // namespace Global 65 } // namespace OHOS 66 #endif