19596a2c1Sopenharmony_ci/* 29596a2c1Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 39596a2c1Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 49596a2c1Sopenharmony_ci * you may not use this file except in compliance with the License. 59596a2c1Sopenharmony_ci * You may obtain a copy of the License at 69596a2c1Sopenharmony_ci * 79596a2c1Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 89596a2c1Sopenharmony_ci * 99596a2c1Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 109596a2c1Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 119596a2c1Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 129596a2c1Sopenharmony_ci * See the License for the specific language governing permissions and 139596a2c1Sopenharmony_ci * limitations under the License. 149596a2c1Sopenharmony_ci */ 159596a2c1Sopenharmony_ci 169596a2c1Sopenharmony_ci#include <cerrno> 179596a2c1Sopenharmony_ci#include <algorithm> 189596a2c1Sopenharmony_ci#include <climits> 199596a2c1Sopenharmony_ci#include <filesystem> 209596a2c1Sopenharmony_ci#include <fstream> 219596a2c1Sopenharmony_ci#include <dirent.h> 229596a2c1Sopenharmony_ci#include <mutex> 239596a2c1Sopenharmony_ci#include <stdexcept> 249596a2c1Sopenharmony_ci#include <string> 259596a2c1Sopenharmony_ci#include <sys/stat.h> 269596a2c1Sopenharmony_ci#include <vector> 279596a2c1Sopenharmony_ci#include "accesstoken_kit.h" 289596a2c1Sopenharmony_ci#include "i18n_hilog.h" 299596a2c1Sopenharmony_ci#include "ipc_skeleton.h" 309596a2c1Sopenharmony_ci#include "locale_config.h" 319596a2c1Sopenharmony_ci#include "parameter.h" 329596a2c1Sopenharmony_ci#include "tokenid_kit.h" 339596a2c1Sopenharmony_ci#include "unicode/localebuilder.h" 349596a2c1Sopenharmony_ci#include "utils.h" 359596a2c1Sopenharmony_ci 369596a2c1Sopenharmony_cinamespace OHOS { 379596a2c1Sopenharmony_cinamespace Global { 389596a2c1Sopenharmony_cinamespace I18n { 399596a2c1Sopenharmony_ciusing namespace std; 409596a2c1Sopenharmony_cistatic const std::string PSEUDO_LOCALE_TAG = "en-XA"; 419596a2c1Sopenharmony_cistatic const std::string PSEUDO_START_TAG = "{"; 429596a2c1Sopenharmony_cistatic const std::string PSEUDO_END_TAG = "}"; 439596a2c1Sopenharmony_ciconstexpr const char *TIMEZONE_LIST_CONFIG_PATH = "/system/etc/zoneinfo/timezone_list.cfg"; 449596a2c1Sopenharmony_ciconstexpr const char *DISTRO_TIMEZONE_LIST_CONFIG = "/system/etc/tzdata_distro/timezone_list.cfg"; 459596a2c1Sopenharmony_cistatic std::mutex validLocaleMutex; 469596a2c1Sopenharmony_ci 479596a2c1Sopenharmony_civoid Split(const string &src, const string &sep, vector<string> &dest) 489596a2c1Sopenharmony_ci{ 499596a2c1Sopenharmony_ci if (src == "") { 509596a2c1Sopenharmony_ci return; 519596a2c1Sopenharmony_ci } 529596a2c1Sopenharmony_ci string::size_type begin = 0; 539596a2c1Sopenharmony_ci string::size_type end = src.find(sep); 549596a2c1Sopenharmony_ci while (end != string::npos) { 559596a2c1Sopenharmony_ci dest.push_back(src.substr(begin, end - begin)); 569596a2c1Sopenharmony_ci begin = end + sep.size(); 579596a2c1Sopenharmony_ci end = src.find(sep, begin); 589596a2c1Sopenharmony_ci } 599596a2c1Sopenharmony_ci if (begin != src.size()) { 609596a2c1Sopenharmony_ci dest.push_back(src.substr(begin)); 619596a2c1Sopenharmony_ci } 629596a2c1Sopenharmony_ci} 639596a2c1Sopenharmony_ci 649596a2c1Sopenharmony_civoid Merge(const std::vector<std::string>& src, const std::string& sep, std::string& dest) 659596a2c1Sopenharmony_ci{ 669596a2c1Sopenharmony_ci if (src.size() == 0) { 679596a2c1Sopenharmony_ci dest = ""; 689596a2c1Sopenharmony_ci return; 699596a2c1Sopenharmony_ci } 709596a2c1Sopenharmony_ci dest = src[0]; 719596a2c1Sopenharmony_ci for (size_t i = 1; i < src.size(); ++i) { 729596a2c1Sopenharmony_ci dest += sep; 739596a2c1Sopenharmony_ci dest += src[i]; 749596a2c1Sopenharmony_ci } 759596a2c1Sopenharmony_ci} 769596a2c1Sopenharmony_ci 779596a2c1Sopenharmony_cistd::string ReadSystemParameter(const char *paramKey, const int paramLength) 789596a2c1Sopenharmony_ci{ 799596a2c1Sopenharmony_ci char param[paramLength]; 809596a2c1Sopenharmony_ci int status = GetParameter(paramKey, "", param, paramLength); 819596a2c1Sopenharmony_ci if (status > 0) { 829596a2c1Sopenharmony_ci return param; 839596a2c1Sopenharmony_ci } 849596a2c1Sopenharmony_ci return ""; 859596a2c1Sopenharmony_ci} 869596a2c1Sopenharmony_ci 879596a2c1Sopenharmony_ciint32_t ConvertString2Int(const string &numberStr, int32_t& status) 889596a2c1Sopenharmony_ci{ 899596a2c1Sopenharmony_ci if (!numberStr.empty() && std::all_of(numberStr.begin(), numberStr.end(), ::isdigit)) { 909596a2c1Sopenharmony_ci try { 919596a2c1Sopenharmony_ci return std::stoi(numberStr); 929596a2c1Sopenharmony_ci } catch (const std::invalid_argument &except) { 939596a2c1Sopenharmony_ci status = -1; 949596a2c1Sopenharmony_ci return -1; 959596a2c1Sopenharmony_ci } catch (const std::out_of_range &except) { 969596a2c1Sopenharmony_ci status = -1; 979596a2c1Sopenharmony_ci return -1; 989596a2c1Sopenharmony_ci } catch (...) { 999596a2c1Sopenharmony_ci status = -1; 1009596a2c1Sopenharmony_ci HILOG_ERROR_I18N("ConvertString2Int: unknow error. numberStr: %{public}s.", numberStr.c_str()); 1019596a2c1Sopenharmony_ci return -1; 1029596a2c1Sopenharmony_ci } 1039596a2c1Sopenharmony_ci } else { 1049596a2c1Sopenharmony_ci status = -1; 1059596a2c1Sopenharmony_ci return -1; 1069596a2c1Sopenharmony_ci } 1079596a2c1Sopenharmony_ci} 1089596a2c1Sopenharmony_ci 1099596a2c1Sopenharmony_cibool IsValidLocaleTag(icu::Locale &locale) 1109596a2c1Sopenharmony_ci{ 1119596a2c1Sopenharmony_ci static std::unordered_set<std::string> allValidLocalesLanguageTag; 1129596a2c1Sopenharmony_ci GetAllValidLocalesTag(allValidLocalesLanguageTag); 1139596a2c1Sopenharmony_ci std::string languageTag = locale.getLanguage() == nullptr ? "" : locale.getLanguage(); 1149596a2c1Sopenharmony_ci if (allValidLocalesLanguageTag.find(languageTag) == allValidLocalesLanguageTag.end()) { 1159596a2c1Sopenharmony_ci HILOG_ERROR_I18N("GetTimePeriodName does not support this languageTag: %{public}s", languageTag.c_str()); 1169596a2c1Sopenharmony_ci return false; 1179596a2c1Sopenharmony_ci } 1189596a2c1Sopenharmony_ci return true; 1199596a2c1Sopenharmony_ci} 1209596a2c1Sopenharmony_ci 1219596a2c1Sopenharmony_civoid GetAllValidLocalesTag(std::unordered_set<std::string>& allValidLocalesLanguageTag) 1229596a2c1Sopenharmony_ci{ 1239596a2c1Sopenharmony_ci static bool init = false; 1249596a2c1Sopenharmony_ci if (init) { 1259596a2c1Sopenharmony_ci return; 1269596a2c1Sopenharmony_ci } 1279596a2c1Sopenharmony_ci std::lock_guard<std::mutex> matchLocaleLock(validLocaleMutex); 1289596a2c1Sopenharmony_ci if (init) { 1299596a2c1Sopenharmony_ci return; 1309596a2c1Sopenharmony_ci } 1319596a2c1Sopenharmony_ci int32_t validCount = 1; 1329596a2c1Sopenharmony_ci const icu::Locale *validLocales = icu::Locale::getAvailableLocales(validCount); 1339596a2c1Sopenharmony_ci for (int i = 0; i < validCount; i++) { 1349596a2c1Sopenharmony_ci const char* language = validLocales[i].getLanguage(); 1359596a2c1Sopenharmony_ci if (language != nullptr) { 1369596a2c1Sopenharmony_ci allValidLocalesLanguageTag.insert(language); 1379596a2c1Sopenharmony_ci } 1389596a2c1Sopenharmony_ci } 1399596a2c1Sopenharmony_ci init = true; 1409596a2c1Sopenharmony_ci} 1419596a2c1Sopenharmony_ci 1429596a2c1Sopenharmony_cibool CheckTzDataFilePath(const std::string &filePath) 1439596a2c1Sopenharmony_ci{ 1449596a2c1Sopenharmony_ci char *realpathRes = nullptr; 1459596a2c1Sopenharmony_ci realpathRes = realpath(filePath.c_str(), nullptr); 1469596a2c1Sopenharmony_ci if (realpathRes == nullptr) { 1479596a2c1Sopenharmony_ci return false; 1489596a2c1Sopenharmony_ci } 1499596a2c1Sopenharmony_ci std::ifstream file(filePath.c_str()); 1509596a2c1Sopenharmony_ci if (!file.good()) { 1519596a2c1Sopenharmony_ci file.close(); 1529596a2c1Sopenharmony_ci free(realpathRes); 1539596a2c1Sopenharmony_ci return false; 1549596a2c1Sopenharmony_ci } 1559596a2c1Sopenharmony_ci file.close(); 1569596a2c1Sopenharmony_ci free(realpathRes); 1579596a2c1Sopenharmony_ci realpathRes = nullptr; 1589596a2c1Sopenharmony_ci return true; 1599596a2c1Sopenharmony_ci} 1609596a2c1Sopenharmony_ci 1619596a2c1Sopenharmony_cistd::string StrReplaceAll(const std::string& str, 1629596a2c1Sopenharmony_ci const std::string& target, const std::string& replace) 1639596a2c1Sopenharmony_ci{ 1649596a2c1Sopenharmony_ci std::string::size_type pos = 0; 1659596a2c1Sopenharmony_ci std::string result = str; 1669596a2c1Sopenharmony_ci if (replace.empty() || target.compare(replace) == 0) { 1679596a2c1Sopenharmony_ci return result; 1689596a2c1Sopenharmony_ci } 1699596a2c1Sopenharmony_ci while ((pos = result.find(target)) != std::string::npos) { 1709596a2c1Sopenharmony_ci result.replace(pos, target.length(), replace); 1719596a2c1Sopenharmony_ci } 1729596a2c1Sopenharmony_ci return result; 1739596a2c1Sopenharmony_ci} 1749596a2c1Sopenharmony_ci 1759596a2c1Sopenharmony_cistd::string GetISO3Language(const string& language) 1769596a2c1Sopenharmony_ci{ 1779596a2c1Sopenharmony_ci UErrorCode icuStatus = U_ZERO_ERROR; 1789596a2c1Sopenharmony_ci icu::Locale locale = icu::Locale::forLanguageTag(language.data(), icuStatus); 1799596a2c1Sopenharmony_ci if (U_FAILURE(icuStatus) || !IsValidLocaleTag(locale)) { 1809596a2c1Sopenharmony_ci return ""; 1819596a2c1Sopenharmony_ci } 1829596a2c1Sopenharmony_ci return locale.getISO3Language(); 1839596a2c1Sopenharmony_ci} 1849596a2c1Sopenharmony_ci 1859596a2c1Sopenharmony_cistd::string GetISO3Country(const string& country) 1869596a2c1Sopenharmony_ci{ 1879596a2c1Sopenharmony_ci UErrorCode icuStatus = U_ZERO_ERROR; 1889596a2c1Sopenharmony_ci icu::Locale locale; 1899596a2c1Sopenharmony_ci if (LocaleConfig::IsValidRegion(country)) { 1909596a2c1Sopenharmony_ci locale = icu::LocaleBuilder().setLanguage("zh").setRegion(country).build(icuStatus); 1919596a2c1Sopenharmony_ci } else if (LocaleConfig::IsValidTag(country)) { 1929596a2c1Sopenharmony_ci locale = icu::Locale::forLanguageTag(country.data(), icuStatus); 1939596a2c1Sopenharmony_ci } else { 1949596a2c1Sopenharmony_ci return ""; 1959596a2c1Sopenharmony_ci } 1969596a2c1Sopenharmony_ci if (U_FAILURE(icuStatus) || !IsValidLocaleTag(locale)) { 1979596a2c1Sopenharmony_ci return ""; 1989596a2c1Sopenharmony_ci } 1999596a2c1Sopenharmony_ci return locale.getISO3Country(); 2009596a2c1Sopenharmony_ci} 2019596a2c1Sopenharmony_ci 2029596a2c1Sopenharmony_cibool FileExist(const std::string& path) 2039596a2c1Sopenharmony_ci{ 2049596a2c1Sopenharmony_ci bool status = false; 2059596a2c1Sopenharmony_ci try { 2069596a2c1Sopenharmony_ci status = std::filesystem::exists(path.c_str()); 2079596a2c1Sopenharmony_ci } catch (const std::filesystem::filesystem_error &except) { 2089596a2c1Sopenharmony_ci HILOG_ERROR_I18N("utils: FileExist failed because filesystem_error, error message: %{public}s.", 2099596a2c1Sopenharmony_ci except.code().message().c_str()); 2109596a2c1Sopenharmony_ci return false; 2119596a2c1Sopenharmony_ci } catch (const std::__h::__fs::filesystem::filesystem_error &except) { 2129596a2c1Sopenharmony_ci HILOG_ERROR_I18N("utils: FileExist failed because filesystem_error, error message: %{public}s.", 2139596a2c1Sopenharmony_ci except.code().message().c_str()); 2149596a2c1Sopenharmony_ci return false; 2159596a2c1Sopenharmony_ci } catch (const std::bad_alloc &except) { 2169596a2c1Sopenharmony_ci HILOG_ERROR_I18N("utils: FileExist failed because bad_alloc, error message: %{public}s.", 2179596a2c1Sopenharmony_ci except.what()); 2189596a2c1Sopenharmony_ci return false; 2199596a2c1Sopenharmony_ci } 2209596a2c1Sopenharmony_ci return status; 2219596a2c1Sopenharmony_ci} 2229596a2c1Sopenharmony_ci 2239596a2c1Sopenharmony_cibool FileCopy(const std::string& srcPath, const std::string& dstPath) 2249596a2c1Sopenharmony_ci{ 2259596a2c1Sopenharmony_ci try { 2269596a2c1Sopenharmony_ci std::filesystem::copy(srcPath.c_str(), dstPath.c_str()); 2279596a2c1Sopenharmony_ci return true; 2289596a2c1Sopenharmony_ci } catch (const std::filesystem::filesystem_error &except) { 2299596a2c1Sopenharmony_ci HILOG_ERROR_I18N("utils: FileCopy failed because filesystem_error, error message: %{public}s.", 2309596a2c1Sopenharmony_ci except.code().message().c_str()); 2319596a2c1Sopenharmony_ci } catch (const std::__h::__fs::filesystem::filesystem_error &except) { 2329596a2c1Sopenharmony_ci HILOG_ERROR_I18N("utils: FileCopy failed because filesystem_error, error message: %{public}s.", 2339596a2c1Sopenharmony_ci except.code().message().c_str()); 2349596a2c1Sopenharmony_ci } catch (const std::bad_alloc &except) { 2359596a2c1Sopenharmony_ci HILOG_ERROR_I18N("utils: FileCopy failed because bad_alloc, error message: %{public}s.", 2369596a2c1Sopenharmony_ci except.what()); 2379596a2c1Sopenharmony_ci } 2389596a2c1Sopenharmony_ci return false; 2399596a2c1Sopenharmony_ci} 2409596a2c1Sopenharmony_ci 2419596a2c1Sopenharmony_cibool IsLegalPath(const std::string& path) 2429596a2c1Sopenharmony_ci{ 2439596a2c1Sopenharmony_ci if (path.find("./") != std::string::npos || 2449596a2c1Sopenharmony_ci path.find("../") != std::string::npos) { 2459596a2c1Sopenharmony_ci return false; 2469596a2c1Sopenharmony_ci } 2479596a2c1Sopenharmony_ci return true; 2489596a2c1Sopenharmony_ci} 2499596a2c1Sopenharmony_ci 2509596a2c1Sopenharmony_cibool IsDirExist(const char *path) 2519596a2c1Sopenharmony_ci{ 2529596a2c1Sopenharmony_ci if (!(path && *path)) { 2539596a2c1Sopenharmony_ci return false; 2549596a2c1Sopenharmony_ci } 2559596a2c1Sopenharmony_ci size_t length = strlen(path); 2569596a2c1Sopenharmony_ci if (length > PATH_MAX) { 2579596a2c1Sopenharmony_ci return false; 2589596a2c1Sopenharmony_ci } 2599596a2c1Sopenharmony_ci char resolvedPath[PATH_MAX]; 2609596a2c1Sopenharmony_ci if (realpath(path, resolvedPath) == nullptr) { 2619596a2c1Sopenharmony_ci return false; 2629596a2c1Sopenharmony_ci } 2639596a2c1Sopenharmony_ci struct stat buf; 2649596a2c1Sopenharmony_ci return stat(resolvedPath, &buf) == 0 && S_ISDIR(buf.st_mode); 2659596a2c1Sopenharmony_ci} 2669596a2c1Sopenharmony_ci 2679596a2c1Sopenharmony_cistd::string trim(std::string &s) 2689596a2c1Sopenharmony_ci{ 2699596a2c1Sopenharmony_ci if (s.empty()) { 2709596a2c1Sopenharmony_ci return s; 2719596a2c1Sopenharmony_ci } 2729596a2c1Sopenharmony_ci s.erase(0, s.find_first_not_of(" ")); 2739596a2c1Sopenharmony_ci s.erase(s.find_last_not_of(" ") + 1); 2749596a2c1Sopenharmony_ci return s; 2759596a2c1Sopenharmony_ci} 2769596a2c1Sopenharmony_ci 2779596a2c1Sopenharmony_cibool GetPseudoLocalizationEnforce() 2789596a2c1Sopenharmony_ci{ 2799596a2c1Sopenharmony_ci std::string systemLocale = LocaleConfig::GetSystemLocale(); 2809596a2c1Sopenharmony_ci if (systemLocale.compare(PSEUDO_LOCALE_TAG) == 0) { 2819596a2c1Sopenharmony_ci return true; 2829596a2c1Sopenharmony_ci } 2839596a2c1Sopenharmony_ci return false; 2849596a2c1Sopenharmony_ci} 2859596a2c1Sopenharmony_ci 2869596a2c1Sopenharmony_cistd::string PseudoLocalizationProcessor(const std::string &input) 2879596a2c1Sopenharmony_ci{ 2889596a2c1Sopenharmony_ci return PseudoLocalizationProcessor(input, GetPseudoLocalizationEnforce()); 2899596a2c1Sopenharmony_ci} 2909596a2c1Sopenharmony_ci 2919596a2c1Sopenharmony_cistd::string PseudoLocalizationProcessor(const std::string &input, bool ifEnforce) 2929596a2c1Sopenharmony_ci{ 2939596a2c1Sopenharmony_ci if (ifEnforce) { 2949596a2c1Sopenharmony_ci return PSEUDO_START_TAG + input + PSEUDO_END_TAG; 2959596a2c1Sopenharmony_ci } 2969596a2c1Sopenharmony_ci return input; 2979596a2c1Sopenharmony_ci} 2989596a2c1Sopenharmony_ci 2999596a2c1Sopenharmony_cibool CheckSystemPermission() 3009596a2c1Sopenharmony_ci{ 3019596a2c1Sopenharmony_ci uint64_t tokenId = IPCSkeleton::GetCallingFullTokenID(); 3029596a2c1Sopenharmony_ci uint32_t callerToken = IPCSkeleton::GetCallingTokenID(); 3039596a2c1Sopenharmony_ci bool isSystemApp = Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(tokenId); 3049596a2c1Sopenharmony_ci Security::AccessToken::ATokenTypeEnum tokenType = 3059596a2c1Sopenharmony_ci Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(callerToken); 3069596a2c1Sopenharmony_ci bool isShell = tokenType == Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL; 3079596a2c1Sopenharmony_ci bool isNative = tokenType == Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE; 3089596a2c1Sopenharmony_ci if (!isSystemApp && !isShell && !isNative) { 3099596a2c1Sopenharmony_ci HILOG_ERROR_I18N("CheckSystemPermission failed, because current app is not system app."); 3109596a2c1Sopenharmony_ci return false; 3119596a2c1Sopenharmony_ci } 3129596a2c1Sopenharmony_ci return true; 3139596a2c1Sopenharmony_ci} 3149596a2c1Sopenharmony_ci 3159596a2c1Sopenharmony_cistd::set<std::string> GetTimeZoneAvailableIDs(I18nErrorCode &errorCode) 3169596a2c1Sopenharmony_ci{ 3179596a2c1Sopenharmony_ci if (availableIDs.size() != 0) { 3189596a2c1Sopenharmony_ci return availableIDs; 3199596a2c1Sopenharmony_ci } 3209596a2c1Sopenharmony_ci struct stat s; 3219596a2c1Sopenharmony_ci const char *tzIdConfigPath = stat(DISTRO_TIMEZONE_LIST_CONFIG, &s) == 0 ? 3229596a2c1Sopenharmony_ci DISTRO_TIMEZONE_LIST_CONFIG : TIMEZONE_LIST_CONFIG_PATH; 3239596a2c1Sopenharmony_ci std::unique_ptr<char[]> resolvedPath = std::make_unique<char[]>(PATH_MAX + 1); 3249596a2c1Sopenharmony_ci if (realpath(tzIdConfigPath, resolvedPath.get()) == nullptr) { 3259596a2c1Sopenharmony_ci HILOG_ERROR_I18N("Get realpath failed, errno: %{public}d.", errno); 3269596a2c1Sopenharmony_ci return availableIDs; 3279596a2c1Sopenharmony_ci } 3289596a2c1Sopenharmony_ci std::ifstream file(resolvedPath.get()); 3299596a2c1Sopenharmony_ci if (!file.good()) { 3309596a2c1Sopenharmony_ci HILOG_ERROR_I18N("Open timezone list config file failed."); 3319596a2c1Sopenharmony_ci return availableIDs; 3329596a2c1Sopenharmony_ci } 3339596a2c1Sopenharmony_ci std::string line; 3349596a2c1Sopenharmony_ci while (std::getline(file, line)) { 3359596a2c1Sopenharmony_ci if (line.length() == 0) { 3369596a2c1Sopenharmony_ci break; 3379596a2c1Sopenharmony_ci } 3389596a2c1Sopenharmony_ci line.resize(line.find_last_not_of("\r\n") + 1); 3399596a2c1Sopenharmony_ci availableIDs.insert(line); 3409596a2c1Sopenharmony_ci } 3419596a2c1Sopenharmony_ci file.close(); 3429596a2c1Sopenharmony_ci return availableIDs; 3439596a2c1Sopenharmony_ci} 3449596a2c1Sopenharmony_ci 3459596a2c1Sopenharmony_cibool RegexSearchNoExcept(const std::string& str, std::smatch& match, const std::regex& regex) 3469596a2c1Sopenharmony_ci{ 3479596a2c1Sopenharmony_ci try { 3489596a2c1Sopenharmony_ci return std::regex_search(str, match, regex); 3499596a2c1Sopenharmony_ci } catch (const std::regex_error &except) { 3509596a2c1Sopenharmony_ci return false; 3519596a2c1Sopenharmony_ci } 3529596a2c1Sopenharmony_ci} 3539596a2c1Sopenharmony_ci} // namespace I18n 3549596a2c1Sopenharmony_ci} // namespace Global 3559596a2c1Sopenharmony_ci} // namespace OHOS