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 <string>
19 #include <vector>
20 #include <unordered_set>
21 #include <unicode/locid.h>
22 #include "set"
23 #include "i18n_types.h"
24 
25 namespace OHOS {
26 namespace Global {
27 namespace I18n {
28 static const uint32_t BYTE_ARRAY_OFFSET_FIRST = 24;
29 static const uint32_t BYTE_ARRAY_OFFSET_SECOND = 16;
30 static const uint32_t BYTE_ARRAY_OFFSET_THIRD = 8;
31 static const uint32_t BYTE_ARRAY_INDEX_THIRD = 3;
32 static std::set<std::string> availableIDs;
33 
34 void Split(const std::string &src, const std::string &sep, std::vector<std::string> &dest);
35 std::string ReadSystemParameter(const char *paramKey, const int paramLength);
36 int32_t ConvertString2Int(const std::string &numberStr, int32_t& status);
37 bool IsValidLocaleTag(icu::Locale &locale);
38 void GetAllValidLocalesTag(std::unordered_set<std::string>& allValidLocalesLanguageTag);
39 bool CheckTzDataFilePath(const std::string &filePath);
40 std::string StrReplaceAll(const std::string& str,
41     const std::string& target, const std::string& replace);
42 std::string GetISO3Language(const std::string& language);
43 std::string GetISO3Country(const std::string& country);
44 std::string trim(std::string &s);
45 bool FileExist(const std::string& path);
46 bool FileCopy(const std::string& srcPath, const std::string& dstPath);
47 bool IsLegalPath(const std::string& path);
48 void Split(const std::string &src, const std::string &sep, std::vector<std::string> &dest);
49 bool IsDirExist(const char *path);
50 bool GetPseudoLocalizationEnforce();
51 std::string PseudoLocalizationProcessor(const std::string &input);
52 std::string PseudoLocalizationProcessor(const std::string &input, bool ifEnforce);
53 bool CheckSystemPermission();
54 size_t ConvertBytesToSizeT(const char *byteArray);
55 std::set<std::string> GetTimeZoneAvailableIDs(I18nErrorCode &errorCode);
56 } // namespace I18n
57 } // namespace Global
58 } // namespace OHOS
59 #endif