• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_RESOURCE_MANAGER_UTILS_H
16 #define OHOS_RESOURCE_MANAGER_UTILS_H
17 #include <cstddef>
18 #include <cstdint>
19 #include <set>
20 #include "res_locale.h"
21 #include "rstate.h"
22 
23 namespace OHOS {
24 namespace Global {
25 namespace Resource {
26 class Utils {
27 public:
28     static bool IsAlphaString(const char *s, int32_t len);
29 
30     static bool IsNumericString(const char *s, int32_t len);
31 
32     static bool IsStrEmpty(const char *s);
33 
34     static size_t StrLen(const char *s);
35 
36     static uint16_t EncodeLanguage(const char *language);
37 
38     static uint16_t EncodeLanguageByResLocale(const ResLocale *locale);
39 
40     static uint32_t EncodeScript(const char *script);
41 
42     static uint32_t EncodeScriptByResLocale(const ResLocale *locale);
43 
44     static void DecodeScript(uint32_t encodeScript, char *outValue);
45 
46     static uint16_t EncodeRegion(const char *region);
47 
48     static uint16_t EncodeRegionByResLocale(const ResLocale *locale);
49 
50     static uint64_t EncodeLocale(const char *language,
51                                  const char *script,
52                                  const char *region);
53 
54     static RState ConvertColorToUInt32(const char *s, uint32_t &outValue);
55 
56     static std::unique_ptr<uint8_t[]> LoadResourceFile(const std::string &path, int &len);
57 
58     static RState EncodeBase64(std::unique_ptr<uint8_t[]> &data, int srcLen,
59                               const std::string &imgType, std::string &outValue);
60 
61     static constexpr float DPI_BASE = 160.0f;
62 
63     static bool endWithTail(const std::string& path, const std::string& tail);
64 
65     static bool isFileExist(const std::string& filePath);
66 
67     static bool ContainsTail(std::string hapPath, std::set<std::string> tailSet);
68 
69     static const std::set<std::string> tailSet;
70 private:
71 
72     static uint16_t EncodeLanguageOrRegion(const char *str, char base);
73 
74     static bool StrCompare(const char *left, const char *right, size_t len, bool isCaseSensitive);
75     static constexpr uint64_t ROOT_LOCALE = 0x0;
76     static constexpr uint16_t NULL_LANGUAGE = 0x00;
77     static constexpr uint16_t NULL_REGION = 0x00;
78     static constexpr uint16_t NULL_SCRIPT = 0x0000;
79     static constexpr uint64_t NULL_LOCALE = 0x0;
80 };
81 } // namespace Resource
82 } // namespace Global
83 } // namespace OHOS
84 #endif